#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#define F first
#define S second
#include<queue>
#include <sstream>
#define endl '\n'
#define lli long long int
#define pairs pair<int,int>
#define ld long double
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
//first try to write all condition on copy then go for implement
ll pows(ll a,ll n,ll m)
{
	a=a%m;
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1||n==0)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
		return false;
			}	
	}
	return true;
}
const int N=100005;

int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
  cout.tie(0);
ll n;
cin>>n;
string s;
cin>>s;
int flip=0;
string s1;
string s2;
for(int i=0;i<n;i++)
{
s1.pb(s[i]);	
}
for(int i=n;i<2*n;i++)
{
	s2.pb(s[i]);
}
int q;
cin>>q;
while(q--)
{
ll t,a,b;
cin>>t>>a>>b;
if(t==1)
{
if(flip==0)
{
if(a>n)
{
	a=a-n;
	b=b-n;
	a--;
	b--;
	swap(s2[a],s2[b]);
}
else if(a<=n&&b>n)
{
  a--;
	b=b-n;
	b--;
swap(s1[a],s2[b]);
}
else{
	a--;
	b--;
swap(s1[a],s1[b]);
}
}
else
{
if(a>n)
{
	a=a-n;
	b=b-n;
	a--;
	b--;
	swap(s1[a],s1[b]);
}
else if(a<=n&&b>n)
{
a--;
	b=b-n;
	b--;
swap(s2[a],s1[b]);
}
else{
	a--;
	b--;
swap(s2[a],s2[b]);
}	
}
}	
else
{
flip=flip^1;
}
}
if(flip==0)
{
cout<<s1<<s2<<endl;	
}
else
{
cout<<s2<<s1<<endl;	
}

}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;	

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define nl cout<<"\n"
#define MOD(x) ((x%P)+P)%P
#define vec(v) loop(i,0,v.size()) cout<<v[i]<<" "; nl
const int N = 1000005;
const ll P = 1000000007;
const ll INF = 1e17;
const double eps = 1e-6;

int main()
{
	fastio();

	int n; cin>>n;
	vector<ll> a(n), t(n);

	for(int i=0; i<n; i++)
		cin>>a[i]>>t[i];

	stack<pair<ll,ll>> st;

	ll sum = 0;
	for(int i=n-1; i>=0; i--)
	{
		if(t[i]==1)
			sum += a[i];
		else if(t[i]==2)
			st.push({2, a[i]+sum});
		else
			st.push({3, a[i]+sum});
	}

	ll mn = -INF, mx = INF;

	while(st.size())
	{
		pair<ll,ll> now = st.top();
		st.pop();

		if(now.f == 2)
		{
			mn = max(mn, now.s);
			if(mn > mx)
				mx = mn;
		}
		else
		{
			mx = min(mx, now.s);
			if(mx < mn)
				mn = mx;
		}
	}
	
	int q; cin>>q;
	for(int i=0; i<q; i++)
	{
		ll temp; cin>>temp;
		temp += sum;

		temp = max(temp, mn);
		temp = min(temp, mx);

		cout<<temp,nl;
	}

	cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}