#include <bits/stdc++.h>
#define debug(x) cout << "[" << #x << " = " << x << "] "
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

/*wa? coloca long long que passa;
testar casos, n = 0? n = 1? 
dp: min(solve(l+1,r),solve(l,r-1))?
Uma resposta ótima pode ter tamanho 2?*/

void printa(string s, int cont){
    int n = s.size() / 2;
    if(cont & 1){
        for(int i = 0; i < n; i++)
            swap(s[i], s[i+n]);
    }
    
    cout << s << endl;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    string s;
    cin >> n >> s;
    
    int q, cont = 0;
    cin >> q;
    
    while(q--){
        int t, a, b;
        cin >> t >> a >> b;
        
        if(t == 1){ //troca s[a] por s[b]
            if(a <= n && b <= n && (cont & 1) ){
                swap(s[a-1+n],s[b-1+n]);
            } else if(a > n && b > n && (cont & 1) ){
                swap(s[a-1-n], s[b-1-n]);
            } else {
                if(cont % 2 == 0)
                    swap(s[a-1], s[b-1]);
                else
                    swap(s[b-1-n], s[a-1+n]);
            }
            
        } else { //troca os n primeiros com os n ultimos
            cont++;
        }
    }
    
    printa(s, cont);
    
}

#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
void radd(int &a, int b)
{
	a=add(a,b); 
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
void rmult(int &a, int b)
{
	a=mult(a,b);
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
	
char b[2][2];
int a[2][2];
int c[2][2];
int dp[1111][2];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	if(n==2)
	{
		cout<<1<<'\n'; return 0;
	}
	cin>>b[0][0]>>b[0][1]>>b[1][0]>>b[1][1];
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++) 
		{
			a[i][j]=b[i][j]-'A';
		}
	}	
	if(a[0][1]==0)
	{
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++) 
			{
				c[i][j]=(a[j^1][i^1]^1);
			}
		}
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++) 
			{
				a[i][j]=c[i][j];
			}
		}
	}
	//assume A...B B
	if(a[1][1]==1)
	{
		cout<<1<<'\n'; return 0;
	}
	//assume B...A B
	if(a[1][0]==1)
	{
		dp[1][1]=1; //length 1, end with 0
		for(int i=2;i<=n;i++)
		{
			dp[i][0]=add(dp[i-1][0],dp[i-1][1]);
			dp[i][1]=dp[i-1][0];
		}
		cout<<dp[n][0]<<'\n';
	}
	else
	{
		//n>2
		cout<<modpow(2,n-3)<<'\n';
	}
}
