/* dont stick to an approach */
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <cstdlib>

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ldb;

#define PB push_back

#define For(i, n) for (ll i = 0; i < n; i++)

#define PYES cout<<"YES\n"
#define PNO cout<<"NO\n"
#define PYes cout<<"Yes\n"
#define PNo cout<<"No\n"

#define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

const int M=4;

using namespace std;

//--------------------------------------------functions--------------------------------------------------------//

ll power(ll a,ll b){int result=1;while(b>0){if(b%2 == 1){result *= a;}a *= a;b /= 2;}return result;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x){return ((x%M + M)%M);}
ll add(ll a, ll b){return mod(mod(a)+mod(b));}
ll mul(ll a, ll b){return mod(mod(a)*mod(b));}
ll powerM(ll a,ll b){ll res=1;while(b){if(b%2==1){res=mul(a,res);}a=mul(a,a);b/=2;}return res;}
//------------------------------------sieve of erantothenes----------------------------------------------------//

vector<bool> sieve_of_eratothenes(ll n){
    vector<bool> a(n+1,1);
    a[0]=0;
    a[1]=0;
    for(ll i=2;i<=sqrt(n);i++){
        if(a[i]==1){
            for(ll j=2;i*j<=n;j++){
                a[j*i]=0;
            }
        }
    }
    return a;
}
//----------------------------------------nCr mod ---------------------------------------------------------------//
ll modInverse(ll n){
    return powerM(n,M-2);
}
ll nCrM(ll n,ll r){
    if(n<r) return 0;
    if(r==0) return 1;
    vector<ll> fact(n+1);
    fact[0]=1;
    for(ll i=1;i<=n;i++){
        fact[i]=mul(fact[i-1],i);
    }
    return mul(mul(fact[n],modInverse(fact[r])),modInverse(fact[n-r]));
}

//-----------------------------------------------solve--------------------------------------------------------//

void solve(){
    ll a,b,c;cin>>a>>b>>c;
    a%=10;
    if(a==5||a==0||a==1||a==6){
        cout<<a<<endl;
    }else if(a==4||a==9){
        if (b%2==0){
            if(a==4){
                cout<<6<<endl;
            }else{
                cout<<1<<endl;
            }
        }else{
            if(a==4){
                cout<<4<<endl;
            }else{
                cout<<9<<endl;
            }
        }
    }else{
        ll d=powerM(b,c);
        if(d==0){
            if(a==2){
                cout<<6<<endl;
            }else if(a==3){
                cout<<1<<endl;
            }else if(a==7){
                cout<<1<<endl;
            }else if(a==8){
                cout<<6<<endl;
            }
        }else if(d==1){
            if(a==2){
                cout<<2<<endl;
            }else if(a==3){
                cout<<3<<endl;
            }else if(a==7){
                cout<<7<<endl;
            }else if(a==8){
                cout<<8<<endl;
            }
        }else if(d==2){
            if(a==2){
                cout<<4<<endl;
            }else if(a==3){
                cout<<9<<endl;
            }else if(a==7){
                cout<<9<<endl;
            }else if(a==8){
                cout<<4<<endl;
            }
        }else if(d==3){
            if(a==2){
                cout<<8<<endl;
            }else if(a==3){
                cout<<7<<endl;
            }else if(a==7){
                cout<<3<<endl;
            }else if(a==8){
                cout<<2<<endl;
            }
        }
    }
}

int main(){
    Fas;

//    ll t=0;
//    cin>>t;
//    while(t--)
        solve();

    return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
char s[N];
int main()
{
	int n,q;
	cin>>n;
	scanf("%s",s+1);
	cin>>q;
	int t,a,b,now=0;
	while(q--)
	{
		cin>>t>>a>>b;
		if(t==2)
			now++;
		else
		{
			if(now&1)
			{
				if(a<=n) a+=n;
				else a-=n;
				if(b<=n) b+=n;
				else b-=n;
			}
			swap(s[a],s[b]);
		}
	}
	if(now&1)
	{
		for(int i=n+1;i<=2*n;i++) cout<<s[i];
		for(int i=1;i<=n;i++) cout<<s[i];
	}
	else
		for(int i=1;i<=2*n;i++) cout<<s[i];
	return 0;
}
