#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define Q 400005
using namespace std;
#define gc() getchar()
inline bool ig(char c){return c>='0'&&c<='9';}
inline void read(int &oi){char c;int f=1,rs=0;while(c=gc(),(!ig(c))&&c!='-');c^'-'?rs=(c^48):f=-1;while(c=gc(),ig(c))rs=rs*10+(c^48);oi=rs*f;}
inline void print(int oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);}
int n,q;char c[Q];bool flag;
int main(){
	read(n);scanf("%s",c);read(q);
	for(int i=1;i<=q;++i){
		int opt,x,y;read(opt);read(x);read(y);
		if(opt==2)flag^=1;
		else{
			if(flag){
				if(x>n)x-=n;else x+=n;
				if(y>n)y-=n;else y+=n;
			}
			char ch=c[x-1];
			c[x-1]=c[y-1];c[y-1]=ch;
		}
	}
	if(flag){
		for(int i=n;i<=2*n-1;++i)putchar(c[i]);
		for(int i=0;i<=n-1;++i)putchar(c[i]);putchar('\n');
	}
	else printf("%s\n",c);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}

void Main(){
    int N,M; cin >> N >> M;
    VI A(N); REP(i,N) cin >> A[i];
    VI B(M); REP(i,M) cin >> B[i];

    ll dp[N+1][M+1]; REP(i,N+1)REP(j,M+1) dp[i][j] = LINF;
    dp[0][0] = 0;
    REP(i,N) dp[i+1][0] = i+1;
    REP(i,M) dp[0][i+1] = i+1;

    ll cummin[N+1][M+1]; REP(i,N+1)REP(j,M+1) cummin[i][j] = LINF;
    cummin[0][0] = 0;
    REP(i,N) cummin[i+1][0] = i+1;
    REP(i,M) cummin[0][i+1] = i+1;

    REP(i,N)REP(j,M){
        // 取り除く場合
        chmin(dp[i+1][j+1], dp[i][j]+2);
        chmin(dp[i+1][j+1], dp[i][j+1]+1);
        chmin(dp[i+1][j+1], dp[i+1][j]+1);

        // 残す場合
        if(A[i]==B[j]) chmin(dp[i+1][j+1], dp[i][j]);
        else chmin(dp[i+1][j+1], dp[i][j]+1);
    }
    ll ans = dp[N][M];
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}