	#include<bits/stdc++.h>
	using namespace std;
	#define N 200005
	#define pb push_back
	#define ll long long
	#define mod 1000000007
	ll jc[N],ans,ny[N],er[N];
	ll ksm(ll x,ll y){
		ll ret=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ret=ret*x%mod;return ret;
	}
	ll C(int n,int m){
		return jc[n]*ny[m]%mod*ny[n-m]%mod;
	}
	int n,i;char c[4][4];
	int main(){
		cin>>n>>c[0][0]>>c[0][1]>>c[1][0]>>c[1][1];
		if(c[0][1]=='B'&&c[1][1]=='B')return cout<<1,0;
		if(c[0][1]=='A'&&c[0][0]=='A')return cout<<1,0;
		if(n<=3)return cout<<1,0;
		for(i=jc[0]=ny[0]=1;i<=n;++i)jc[i]=jc[i-1]*i%mod,ny[i]=ksm(jc[i],mod-2);
		if(c[0][1]=='B'){
			if(c[1][0]=='A'){
				cout<<ksm(2,n-3)<<"\n";
			}
			else{
				n-=2;
				for(i=0;(i<<1)<=n;++i){
					ans+=C(n-i,i);
				}
				cout<<ans%mod;
			}
		}
		else {
			if(c[1][0]=='B'){
				cout<<ksm(2,n-3)<<"\n";
			}
			else{
				n-=2;
				for(i=0;(i<<1)<=n;++i){
					ans+=C(n-i,i);
				}
				cout<<ans%mod;
			}
		}
	}
#include <bits/stdc++.h>

using namespace std;

typedef long long i64;

const int MAX_N = 200000 + 5;
const int A = 1e8;

int n[2], N, Q;
int a[2][MAX_N];
i64 ans;

int Root[2], total_node;
struct SegmentNode {
    i64 cnt, sum;
    int ls, rs;
} node[MAX_N * 50];

inline void segment_update(int i) {
    node[i].cnt = node[node[i].ls].cnt + node[node[i].rs].cnt;
    node[i].sum = node[node[i].ls].sum + node[node[i].rs].sum;
}
void segment_modify(int &i, int l, int r, int mp, int mv) {
    i = i ? i : ++ total_node;
    if (l == r) {
        node[i].cnt += mv;
        node[i].sum += 1ll * mv * l;
        return;
    }
    int mid = l + r >> 1;
    if (mp <= mid) {
        segment_modify(node[i].ls, l, mid, mp, mv);
    } else {
        segment_modify(node[i].rs, mid + 1, r, mp, mv);
    }
    segment_update(i);
}
i64 qcnt, qsum;
void segment_query(int i, int l, int r, int ql, int qr) {
    if (!i || ql <= l && r <= qr) {
        qcnt += node[i].cnt;
        qsum += node[i].sum;
        return;
    }
    int mid = l + r >> 1;
    if (ql <= mid) {
        segment_query(node[i].ls, l, mid, ql, qr);
    }
    if (mid + 1 <= qr) {
        segment_query(node[i].rs, mid + 1, r, ql, qr);
    }
}

int main() {
    scanf("%d%d%d", &n[0], &n[1], &Q);
    segment_modify(Root[0], 0, A, 0, n[0]);
    segment_modify(Root[1], 0, A, 0, n[1]);
    for (int i = 1; i <= Q; i ++) {
        int t, x, y;
        scanf("%d%d%d", &t, &x, &y), t --;
        qcnt = qsum = 0;
        segment_query(Root[t ^ 1], 0, A, a[t][x], A);
        ans -= 1ll * (n[t ^ 1] - qcnt) * a[t][x] + qsum;
        segment_modify(Root[t], 0, A, a[t][x], -1);
        a[t][x] = y;
        segment_modify(Root[t], 0, A, a[t][x], 1);
        qcnt = qsum = 0;
        segment_query(Root[t ^ 1], 0, A, a[t][x], A);
        ans += 1ll * (n[t ^ 1] - qcnt) * a[t][x] + qsum;
        printf("%lld\n", ans);
    }
    return 0;
}