#include <iostream>
#include <string>
using namespace std;

int main(void){
	string str, instruction, temp;
	int a,b,q;

	cin >> str;
	cin >> q;

	for (int i = 0; i < q; i++){
		cin >> instruction >> a >> b;
		if (instruction == "replace"){
			cin >> temp;
			str.replace (a, (b-a)+1, temp);
		}
		else if (instruction == "reverse"){
			for (int i = a, j = b; i < ((a + b) / 2)+1; i++, j--){
				char temp = str[j];
				str[j] = str[i];
				str[i] = temp;
			}
		}
		else if (instruction == "print"){
			for (int i = a; i < b + 1; i++){
				cout << str[i];
			}
			cout << "\n";
		}
	}

	return 0;
}
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int n, tmp;
  string s, res, station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  while (cin >> n, n) {
    int key[n];
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      key[i] = tmp;
    }
    cin >> s;
    res = "";
    for (int i = 0; i < s.length(); i++) {
      res += station[(station.find(s[i])-key[i%n]+52)%52];
    }
    cout << res << el;
  }
}