#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pre(i,a,b) for(int i=(b);i>=(a);i--)
#define ios ios::sync_with_stdio(false),cin.tie(0);
#define pb push_back
#define ps push
#define fi first
#define se second
#define ps push
#define Inf 0x3f3f3f3f3f3f3f3f
#define eps 1e-5
typedef long long ll;

const int N=3e5+5;
const int M=2e5+5;
const int mod=998244353;
using namespace std;

ll quick_power_mod(ll a,ll b,ll m)//pow(a,b)%m
{
    a%=m;
  ll result = 1;
  while(b>0)
  {
    if(b&1)
    result=(result*a)%m;
    a=(a*a)%m;
    b>>=1;
  }
  return result;
}
//计算组合数取模
ll comp(ll a,ll b,int p)//composite num C(a,b)%p
{
  if(a<b)return 0;
  if(a==b)return 1;
  if(b>a-b)b=a-b;
  ll ans=1,ca=1,cb=1;
  for(ll i=0;i<b;i++)
  {
    ca=(ca*(a-i))%p;
    cb=(cb*(b-i))%p;
  }
  ans=(ca*quick_power_mod(cb,p-2,p))%p;
  return ans;
}
ll lucas(ll n,ll m,ll p)
{
  ll ans=1;
  while(n&&m&&ans)
  {
    ans=(ans*comp(n%p,m%p,p))%p;//also can be recusive
    n/=p;
    m/=p;
  }
  return ans;
}


ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
string   str;
signed main()
{
  ios;
  int n,q;
  cin>>n>>str>>q;
  int t,a,b;
  int cc=0;
  while(q--){
  	 cin>>t>>a>>b;
  	 if(t==1){
  	 	if(cc%2==0){
		   
  	 	swap(str[a-1],str[b-1]);
		}
		else{
	    if(a<=n){
		a+=n;
		
		}
		else{
			a-=n;
		}
		if(b<=n){
		b+=n;
		
		}
		else{
			b-=n;
		}
		
		swap(str[a-1],str[b-1]);
		}
	 }
	 else{
	 	cc++;
	 //	swap(str[n-1],str[2*n-1]);
	 }
  }
  if(cc%2==0){
  	cout<<str<<endl;
  }
  else{
    for(int i=n;i<2*n;i++){
    	cout<<str[i];
	}	
	for(int i=0;i<n;i++){
		cout<<str[i];
	}
	cout<<endl;
  }
  
  
  

  
  return 0 ;
}

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

#define int long long
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const int N = 1e5 + 5;

struct node{
    int to;
    int cost;
    int k;
    node(int _to, int _cost, int _k){
        to = _to;
        cost = _cost;
        k = _k;
    }
};

vector<node> g[N];

int32_t main() {
    fast;
    int n,m,x,y;
    cin >> n >> m >> x >> y;

    f(i,0,m){
        int u,v,cost,k;
        cin >> u >> v >> cost >> k;
        g[u].pb(node(v, cost, k));
        g[v].pb(node(u, cost, k));
    }

    priority_queue<pii, vector<pii>, greater<pii>> pq;
    vi dis(n+1, 1e18);
    dis[x] = 0;
    pq.push({0, x});

    while(!pq.empty()){
        pii p = pq.top();
        pq.pop();
        int u = p.S;
        int cur = p.F;
        for(int i=0 ; i<g[u].size() ; i++){
            int v = g[u][i].to;
            int cost = g[u][i].cost;
            int k = g[u][i].k;
            int temp = (k - cur % k)%k + cur + cost;
            if(dis[v] > temp){
                dis[v] = temp;
                pq.push({temp, v});
            }
        }
    }

    int ans = dis[y];
    if(ans == 1e18){
        ans = -1;
    }
    cout << ans << "\n";
}