#include<bits/stdc++.h>
#define LL long long
#define pll pair<LL,LL> 
#define mp make_pair
#define fi first
#define se second
using namespace std;
int read(){
	char ch=getchar(); int x=0,fl=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') fl=-1;
	for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch-'0');
	return x*fl;
}
const int N=200005;

int n,m,q,maxn=1e8;
LL a[N],b[N];
void upd(pll &a,pll b){
	a.fi+=b.fi; a.se+=b.se;
}
struct seg{
	int ls[N<<5],rs[N<<5],cnt;
	LL C[N<<5],S[N<<5];
	
	pll qry(int rt,int l,int r,int ql,int qr){
		if(!rt||ql>qr) return mp(0LL,0LL);
		if(ql<=l&&r<=qr) return mp(C[rt],S[rt]);
		int mid=(l+r)>>1;
		pll res=mp(0LL,0LL);
		if(ql<=mid) upd(res,qry(ls[rt],l,mid,ql,qr));
		if(qr>mid) upd(res,qry(rs[rt],mid+1,r,ql,qr));
		return res;
	}
	void mdf(int rt,int l,int r,int pv,LL sgn){
		C[rt]+=sgn; S[rt]+=1LL*sgn*pv;
		if(l==r) return;
		int mid=(l+r)>>1;
		if(pv<=mid){
			if(!ls[rt]) ls[rt]=++cnt;
			mdf(ls[rt],l,mid,pv,sgn);
		}
		else{
			if(!rs[rt]) rs[rt]=++cnt;
			mdf(rs[rt],mid+1,r,pv,sgn);
		}
	}
}t[2];

int main(){
	n=read(); m=read(); q=read();
	t[0].cnt=t[1].cnt=1;
	for(int i=1;i<=n;i++) t[0].mdf(1,0,maxn,a[i]=0,1);
	for(int i=1;i<=m;i++) t[1].mdf(1,0,maxn,b[i]=0,1);
	LL ans=0LL;
	while(q--){
		int opt=read(),x=read(),y=read();
		opt--;
		if(!opt){
			t[0].mdf(1,0,maxn,a[x],-1);
			if(y<a[x]){
				pll tmp=t[1].qry(1,0,maxn,y,a[x]);
				ans-=1LL*a[x]*tmp.fi;
				ans+=1LL*tmp.se;
				tmp=t[1].qry(1,0,maxn,0,y-1);
				ans-=1LL*tmp.fi*a[x];
				ans+=1LL*tmp.fi*y;
			}
			else if(y>a[x]){
				pll tmp=t[1].qry(1,0,maxn,a[x],y);
				ans-=1LL*tmp.se;
				ans+=1LL*y*tmp.fi;
				tmp=t[1].qry(1,0,maxn,0,a[x]-1);
				ans-=1LL*a[x]*tmp.fi;
				ans+=1LL*y*tmp.fi;
			}
			a[x]=y;
			t[0].mdf(1,0,maxn,y,1);
		}
		else{
			t[1].mdf(1,0,maxn,b[x],-1);
			if(y<b[x]){
				pll tmp=t[0].qry(1,0,maxn,y,b[x]);
				ans-=1LL*b[x]*tmp.fi;
				ans+=1LL*tmp.se;
				tmp=t[0].qry(1,0,maxn,0,y-1);
				ans-=1LL*tmp.fi*b[x];
				ans+=1LL*tmp.fi*y;
			}
			else if(y>b[x]){
				pll tmp=t[0].qry(1,0,maxn,b[x],y);
				ans-=1LL*tmp.se;
				ans+=1LL*y*tmp.fi;
				tmp=t[0].qry(1,0,maxn,0,b[x]-1);
				ans-=1LL*b[x]*tmp.fi;
				ans+=1LL*y*tmp.fi;
			}
			b[x]=y;
			t[1].mdf(1,0,maxn,y,1);
		}
		cout<<ans<<'\n';
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e18;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();}
    constexpr bool operator==(const ModInt& r){ return x == r.x;}
    constexpr bool operator!=(const ModInt& r){ return x != r.x;}
    ModInt inv() const {
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n) const {
        ModInt a=1;
        ModInt b=*this;
        while(n>0){
            if(n&1) a*=b;
            b*=b;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

int main(){
    int n;
    cin >> n;
    char aa,ab,ba,bb;
    cin >> aa >> ab >> ba >> bb;

    if(n == 2 || (ab == 'B' && bb == 'B')) cout << 1 << endl;
    else if(ab == 'A' && aa == 'A') cout << 1 << endl;
    else if((ab == 'A' && aa == 'B' && ba == 'B') || (ab == 'B' && bb == 'A' && ba == 'A')){
        cout << mint(2).pow(n-3) << endl;
    }else{
        vector<mint> fib(n,0);
        fib[1] = 1;
        for(int i=2;i<n;i++) fib[i] = fib[i-1] + fib[i-2];
        cout << fib[n-1] << endl;
    }

    return 0;
}