#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define int long long int
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define maxn 200001
vector<vector<pair<int,int>>>v(maxn);
vector<int>pre(maxn);
void dfs(int x,int p,int w)
{
    int val=w;
    if(p!=0)
    {
        val=val^pre[p];
    }
    pre[x]=val;
    for(auto itr:v[x])
    {
        if(itr.fi!=p)
        {
            dfs(itr.fi,x,itr.se);
        }
    }
}
int32_t main()
{
    fastIO;
    int n;
    cin>>n;
    int x,y,val,val1,ans=0;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y>>val; 
        v[x].pb({y,val});
        v[y].pb({x,val});
    }
    dfs(1,0,0);
    
    vector<vector<int>>suf(n+1,vector<int>(61));
    for(int i=n;i>=1;i--)
    {
        for(int j=0;j<=60;j++)
        {
            val1=(int)1<<j;
            if(val1&pre[i])
            {
                suf[i][j]++;
            }
        }
        if(i<n)
        {
            for(int j=0;j<=60;j++)
            {
                suf[i][j]+=suf[i+1][j];
            }
        }
    }
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=60;j++)
        {
            x=n-suf[i+1][j]-i-1;
            int val1=(int)1<<j;
            if(val1&pre[i])
            {
                x++;
                val=val1%mod;
                val=(x*val)%mod;
                ans=(ans+val)%mod;
            }   
            else{
                val=val1%mod;
                val=(suf[i+1][j]*val)%mod;
                ans=(ans+val)%mod;
            }
        }
    }
    cout<<ans<<endl;
}
#include<bits/stdc++.h>
#define FORz(i,t,n) for(int i=t;i<=n;i++)
#define FORf(i,n,t) for(int i=n;i>=t;i--)
#define SCC(x) scanf("%d",&x)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
using namespace std;
const int N=1e5+5;
const ll MOD=1e9+7;
// inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
//ll pow1(ll a,ll b){ll r=1;while(b){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll pow2(ll a,ll b,ll mod){ll r=1;while(b){if(b&1)r=r*a%mod;a=a*a%mod;b>>=1;}return r%mod;}
//ll gcd(ll a,ll b){ll m=a%b;while(m){a=b;b=m;m=a%b;}return b;}
void exgcd(ll a, ll b, ll &d, ll &x, ll &y){if(!b) { d = a; x = 1; y = 0;}else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }}
ll inv(ll a){ll d, x, y;exgcd(a, MOD, d, x, y);return d == 1 ? (x + MOD) % MOD : -1;}struct node{ll mat[105][105];};node mul(node x,node y,int n,ll mod){node tmp;for(int i=0;i<n;i++)for(int j=0;j<n;j++){tmp.mat[i][j]=0;for(int k=0;k<n;k++)tmp.mat[i][j]+=(x.mat[i][k]*y.mat[k][j])%mod;tmp.mat[i][j]%=mod;}return tmp;}
// node matpow(node x,node y,ll num,int n,ll mod){while(num){if(num&1){y=mul(x,y,n,mod);}x=mul(x,x,n,mod);num=num>>1;}return y;}
//for(ll i=2;i<N-1;i++){if(!a[i]) b[++cnt]=i;for(ll j=1;j<=cnt&&i*b[j]<N;j++){a[i*b[j]]=1;if(i%b[j]==0) break;}}
//int find(int x){return a[x]==x?x:a[x]=find(a[x]);}
//void merge(int x,int y){a[find(y)]=a[find(x)];}
ll n,q,t,a,b,z;
string s,j;
int main()
{
    int n;
    cin>>n>>s>>q;
    j=s.substr(n,n)+s.substr(0,n);
    while(q--){
        cin>>t>>a>>b;
        a--,b--;
        if(t==1){
            char x=s[(a+z*n)%(2*n)];
            s[(a+z*n)%(2*n)]=s[(b+z*n)%(2*n)];
            s[(b+z*n)%(2*n)]=x;
            x=j[(a+!z*n)%(2*n)];
            j[(a+!z*n)%(2*n)]=j[(b+!z*n)%(2*n)];
            j[(b+!z*n)%(2*n)]=x;

        }
        else{
            z=!z;
        }
    }
    z?cout<<j:cout<<s;
}
