#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static int IN(void)
{
  int x=0,f=1,c;while(c=getchar(),c<48||c>57){if(c==45)f=-f;}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
typedef struct List{int adj,v,c,d;}edge;
int hsz=0;long minHeap[200001][2],output[2];
static void PUSH(int id,long key)
{
  int i=++hsz,j=i>>1;long sw[2];
  minHeap[i][0]=id,minHeap[i][1]=key;
  while(j)
  {
    if(minHeap[i][1]<minHeap[j][1])
    {
      sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
      minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
      minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
      i=j;j>>=1;
    }else break;
  }
}
static void POP(void)
{
  int i=1,j=i+1;long sw[2];
  output[0]=minHeap[i][0],output[1]=minHeap[i][1];
  minHeap[i][0]=minHeap[hsz][0],minHeap[i][1]=minHeap[hsz--][1];
  while(j<=hsz)
  {
    if(j<hsz&&minHeap[j^1][1]<minHeap[j][1]){j^=1;}
    if(minHeap[j][1]<minHeap[i][1])
    {
      sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
      minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
      minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
      i=j;j=i<<1;
    }else break;
  }
  return;
}
int main(void)
{
  int N=IN(),M=IN(),vis[100000],esz=0,head[100000];
  long dist[100000];edge e[200001];
  rep(i,N){dist[i]=9e18;}
  while(M--)
  {
    int A=IN(),B=IN(),C=IN(),D=IN();
    e[++esz].adj=head[A-1];
    head[A-1]=esz;
    e[esz].v=B;
    e[esz].c=C;
    e[esz].d=D;
    e[++esz].adj=head[B-1];
    head[B-1]=esz;
    e[esz].v=A;
    e[esz].c=C;
    e[esz].d=D;
  }
  dist[0]=0l;
  PUSH(1,0l);
  while(hsz)
  {
    POP();
    long v=output[1];
    if(vis[output[0]-1]){continue;}
    for(int i=head[output[0]-1];i;i=e[i].adj)
    {
      int to=e[i].v;long len=0l;
      if(e[i].d)
      {
        int x=sqrt(e[i].d)-1;
        if(e[i].d/(x+1)>1+e[i].d/(x+2)){x++;}
        if(e[i].d/(x+1)>1+e[i].d/(x+2)){x++;}
        if(v>1l*x){len=1l*e[i].c+1l*e[i].d/(v+1l);}
        else{len=1l*e[i].c+1l*x-v+1l*e[i].d/(1l*x+1l);}
      }else{len=1l*e[i].c;}
      if(dist[to-1]>v+len)
      {
        dist[to-1]=v+len;
        PUSH(to,v+len);
      }
    }
    vis[output[0]-1]=1; 
  }
  if(dist[N-1]==9e18){puts("-1");}else OUT(dist[N-1]);
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(ar) ar.begin(),ar.end()
#define endl '\n'

void swap(string &y,string &z,int a,int b) {
    char k;
    k=y[a];
    y[a]=z[b];
    z[b]=k;
}
void swapin(string &y,int a,int b) {
    char k;
    k=y[a];
    y[a]=y[b];
    y[b]=k;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    string y=s.substr(0,n);
    string z=s.substr(n,n);
    int q;
    cin>>q;
    int kk=0;
    while(q--) {
        int t,a,b;
        cin>>t>>a>>b;
        a--;
        b--;
        
        if(t==1) {
            if(kk%2) {
                if(a<n) {
                    if(b>=n) {
                        b=b-n;
                        swap(z,y,a,b);
                    }
                    else {
                        swapin(z,a,b);
                    }
                }
                else {
                    a=a-n;
                    b=b-n;
                    swapin(y,a,b);
                }
            }
            else {
                if(a<n) {
                    if(b>=n) {
                        b=b-n;
                        swap(y,z,a,b);
                    }
                    else {
                        swapin(y,a,b);
                    }
                }
                else {
                    a=a-n;
                    b=b-n;
                    swapin(z,a,b);
                }
            }
    
            
        }
        else{
            kk++;
        }
    }    
    if(kk%2) {
        cout<<z<<y<<endl;
    }
    else{
        cout<<y<<z<<endl; 
    }  
    

}