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

long long int mod = 1000000007;


void solve(){

	int n;
	cin>>n;
	string s;
	cin>>s;
	int l=0;
	string a,b;
	a = s.substr(0,n);
	b = s.substr(n,n);

	int q;
	cin>>q;

	while(q--){
		int t,x,y;
		cin>>t>>x>>y;
		x--;
		y--;
		if(t==1){
			if(l==0){
				char t;
				if(x<n) t = a[x];
				else t = b[x-n];

				if(x<n) if(y<n) a[x]=a[y]; else a[x]=b[y-n];
				else if(y<n) b[x-n]=a[y]; else b[x-n]=b[y-n];

				if(y<n) a[y]=t; 
				else b[y-n]=t;
			}
			if(l==1){
				char t;
				if(x<n) t = b[x];
				else t = a[x-n];

				if(x<n) if(y<n) b[x]=b[y]; else b[x]=a[y-n];
				else if(y<n) a[x-n]=b[y]; else a[x-n]=a[y-n];

				if(y<n) b[y]=t; 
				else a[y-n]=t;
			}
		}

		if(t==2) l = 1-l;
	}

	if(l==0) cout<<a<<b<<endl;
	else cout<<b<<a<<endl;

	return;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	long long int t=1;
	// cin>>t;

	for(long long int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "talltree"
#define pll pair<ll, ll>
#define pii pair<pll, pll>
#define fi first
#define se second
#define ull unsigned long long

using namespace std;
const ll mod = 1e9+7;
const ll N = 2e5+5;

ll n, m, t, ans, k, a[N], b[N], tong,  cnt, q, c[N];
pll d[N][62];
vector<pll> adj[N];

string s[N];
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
void dfs(ll u, ll p)
{
    for(int i = 0; i < 60; i ++)d[u][i].se = 1;
    for(pll v : adj[u])
    {
        if(v.se == p)continue;
        dfs(v.se, u);
        for(int i = 0; i < 60; i ++)
        {
            if((v.fi >> i) & 1)swap(d[v.se][i].fi, d[v.se][i].se);
            ans = (ans + pw(2, i) * ((d[v.se][i].fi * d[u][i].se % mod + d[u][i].fi * d[v.se][i].se % mod) % mod ) % mod) % mod;
            d[u][i].fi += d[v.se][i].fi;
            d[u][i].se += d[v.se][i].se;
        }
    }
}
void sol()
{
    cin >> n;
    for(int i = 1; i < n; i ++)
    {
        ll x, y, w;
        cin >> x >> y >> w;
        adj[x].pb({w, y});
        adj[y].pb({w, x});
    }
    dfs(1, 0);
    cout << ans;
}
int main()
{
    if(fopen(task".inp", "r")){
       freopen(task".inp", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
3 5
1 2 3 3 1
4 3 2 5 3
2 6 6 2 5
1 2 2 2
2 1 3 3
3 2 3 3
3 5 1 3
*/
