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

const int MaxN=2e5;
const int MaxQ=3e5;
char ss[MaxN+1<<1];

int main(){
	int N, Q, T, A, B;
	
	scanf("%d\n%s\n%d\n",&N,ss,&Q);
	int base=0;
	int L=N<<1;    //L=2*N;
	
	while(Q-->0){
		scanf("%d %d %d",&T,&A,&B);
		if(T==2){
			base^=N;
		}else{// T==1
			A=(A-1+base)%L;
			B=(B-1+base)%L;
			swap(ss[A],ss[B]);
		}
	}
	
	for(int i=0;i<L;i++)
		putchar(ss[(base+i)%L]);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

class UnionFind {
	vector<int>par, sz;
	vector<int>ed;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = ed = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
			ed[i] = 0;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
			ed[x]+=ed[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
			ed[y]+=ed[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
	void add(int x){
		x=find(x);
		ed[x]++;
	}
	int esize(int x){
		return ed[find(x)];
	}
};

//~ int in[500000];
int main(){
	int n;cin>>n;
	UnionFind uf(500000);
	rep(i,n){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		uf.unite(a,b);
		uf.add(a);
	}
	int ans=0;
	rep(i,500000){
		if(uf.find(i)==i){
			ans+=min(uf.size(i),uf.esize(i));
		}
	}
	cout<<ans<<endl;
}