#include<map>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mp make_pair
using namespace std;

map<pair<int,int>,int> m;

struct dsu
{
    int fa[200010],rank[200010];
    
    void init(int n)
    {
        for(int i=1;i<=n;i++)
        {
            fa[i]=i;
        }
    }
    
    int find(int x)
    {
        if(fa[x]==x)
        {
            return x;
        }
        return fa[x]=find(fa[x]);
    }
    
    void union_(int x,int y)
    {
        int fx=find(x);
        int fy=find(y);
        if(fx==fy)
        {
            return ;
        }
        if(rank[fx]<rank[fy])
        {
            fa[fx]=fy;
        }
        else
        {
            fa[fy]=fx;
            if(rank[fx]==rank[fy])
            {
                rank[x]++;
            }
        }
    }
    
    int same(int x,int y)
    {
        return find(x)==find(y);
    }
}a,b;

int main()
{
    //give the fucking vjudge a flying fucking
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    a.init(n);
    b.init(n);
    int from,to;
    for(int i=1;i<=x;i++)
    {
        scanf("%d%d",&from,&to);
        a.union_(from,to);
    }
    for(int i=1;i<=y;i++)
    {
        scanf("%d%d",&from,&to);
        b.union_(from,to);
    }
    for(int i=1;i<=n;i++)
    {
        m[mp(a.find(i),b.find(i))]++;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d ",m[mp(a.find(i),b.find(i))]);
    }
}
#include <iostream>
using namespace std;

void pri(string s,int a,int b){
  cout << s.substr(a,b-a+1) << endl;
}

string rep(string s,int a, int b, string r){
  for(int i=a; i<=b; i++){
    s[i] = r[i-a];
  }
  return s;
}

string rev(string s, int a, int b){
  string tmp = s;
  for(int i=a; i<=b; i++){
    s[i] = tmp[b+a-i];
  }
  return s;
}

int main(){

  int n;
  string s;
  cin >> s >> n;
  for(int i=0; i<n; i++){
    string ope,tar; cin >> ope;
    int a,b;
    //    cout << ope <<endl;
    if(ope == "replace"){
      cin >> a >> b >> tar;
      s = rep(s,a,b,tar);
    }
    if(ope == "print"){
      cin >> a >> b;
      pri(s,a,b);
    }
    if(ope == "reverse"){
      cin >> a >> b;
      s = rev(s,a,b);
    }
  }
}