#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<int> idxs(2*n + 1);
    for (int i = 1; i <= 2*n; i++)
        idxs[i] = i;
    int flag = 0;
    while (q--) {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 1) {
            if (flag) {
                if (a > n)
                    a -= n;
                else
                    a += n;
                if (b > n)
                    b -= n;
                else
                    b += n;
            }
            swap(idxs[a], idxs[b]);
        }
        else {
            flag = !flag;
        }
    }
    if (!flag) {
        for (int i = 1; i <= 2*n; i++)
            cout << s[idxs[i] - 1];
    }
    else {
        for (int i = n + 1; i <= 2*n; i++)
            cout << s[idxs[i] - 1];
        for (int i = 1; i <= n; i++)
            cout << s[idxs[i] - 1];
    }

    return 0;
}
#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;

set<int> s[N];
map<pair<int,int>, int> mp;
int par[N];

int parent(int x) 
{
  if(par[x] != x) par[x] = parent(par[x]);
  return par[x];
}

void join(int x, int y)
{
  x = parent(x);
  y = parent(y);
  if(x == y) return;
  if(s[x].size() > s[y].size())swap(x,y);
  for(int i:s[x])
  {
    s[y].insert(i);
    mp[{y,i}] += mp[{x,i}];
  }
  par[x] = y;
}

int main()
{
  int n,q;
  cin>>n>>q;
  int a[n+1];
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    mp[{i,a[i]}] = 1;
    s[i].insert(a[i]);
    par[i] = i;
  }
  while(q--)
  {
    int t,x,y;
    cin>>t>>x>>y;
    if(t == 1)join(x,y);
    else cout<<mp[{parent(x),y}]<<endl;
  }
}