#include <iostream>
#include <string>

using namespace std;

int main()
{
	string str;
	cin >> str;

	int number_of_instruction;
	cin >> number_of_instruction;

	for (int i = 0; i < number_of_instruction; ++i)
	{
		string instruction;
		int param1, param2;
		string temp_str = "";
		string replace_str = "";
		cin >> instruction >> param1 >> param2;

		if (instruction == "print")
		{
			for (int i = param1; i <= param2 ; ++i)
			{
				temp_str += str[i];
			}
			cout << temp_str << endl;
		}

		if(instruction == "reverse")
		{
			for (int i = 0; i < param1; ++i)
			{
				temp_str += str[i];
			}
			for (int i = param2; i >= param1; --i)
			{
				temp_str += str[i];
			}
			for (int i = param2+1; i < str.size(); ++i)
			{
				temp_str += str[i];
			}
			str = temp_str;
		}

		if(instruction == "replace")
		{
			string replace_str;
			cin >> replace_str;
			str.replace(param1, param2 - param1 + 1, replace_str);
		}

	}
}
#include <bits/stdc++.h>

int main() {
  
  char str[1024];
  char ope[256];
  char obj[1024];
  int q;
  int a, b;
  char temp;

  scanf("%s", str);
  scanf("%d", &q);

  for(int i = 0; i < q; ++i) {
    scanf("%s", ope);
    if( strcmp("replace", ope) == 0 ) {
      scanf("%d %d", &a, &b);
      scanf("%s", obj);
      for(int j = a; j <= b; ++j) {
	str[j] = obj[j-a];
      }
    }
    else if( strcmp("reverse", ope) == 0 ) {
      scanf("%d %d", &a, &b);
      for(int j = a; j <= (a+b)/2; ++j) {
	temp = str[j]; str[j] = str[a+b-j]; str[a+b-j] = temp;
      }
    }
    else if( strcmp("print", ope) == 0 ) {
      scanf("%d %d", &a, &b);
      for(int j = a; j <= b; ++j) {
	printf("%c", str[j]);
      }
      printf("\n");
    }
    else {
      printf("nya------\n");
    }
      
  }
  
  return 0;
}