#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize ("-O3")
#define int long long
#define ld long double
#define endl "\n"

#define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end))
#define umap unordered_map
#define pq priority_queue 
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define w(t) int t; cin>>t; rep(tc,0,t)
#define clr(a,x) memset(a,x,sizeof a)

#define chkbit(x,i) ((x)&(1LL<<(i)))
#define setbit(x,i) ((x)|(1LL<<(i)))
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int mod = 1e9+7;
const int mod2 = 998244353;
const int N = 2e6;
const int inf = 1e18;
const ld PI = 3.141592653589793;

//=====================================================


template<typename... T>
void in(T&... args) {((cin>>args), ...);}
template<typename... T>
void out(T&&... args) {((cout<<args<<" "), ...);}
template<typename... T>
void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;}

int nxt(){int x;cin>>x;return x;}
int add(int a,int b,int mod){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b,int mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
int range(int x,int y,int z) {return (x >= y && x <= z);}

struct customCompare {
    bool operator () (int x, int y) {
        return x>y;
    }
};

//=====================================================


int ModExp(int x, int y, int m){
    int res = 1;
    while (y > 0) {
        if (y & 1) res = (res*x) % m;
        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

int calc(int n) {
    if (n <= 1)
        return 1;
    int x = 1, y = 1;
    for (int i = 2; i <= n; i++) {
        int tmp = (x+y)%mod;
        x = y;
        y = tmp;
    }
    return y;
}

void solve() {

    int n = nxt();
    char aa, ab, ba, bb;
    cin >> aa >> ab >> ba >> bb;

    int ans;
    if (n <= 2)
        ans = 1;
    else if (ab == 'A' && aa == 'A')
        ans = 1;
    else if (ab == 'B' && bb == 'B')
        ans = 1;
    else if (ab == 'A' && aa == 'B' && ba == 'A') 
        ans = calc(n-2);
    else if (ab == 'B' && bb == 'A' && ba == 'B') 
        ans = calc(n-2);
    else 
        ans = ModExp(2, n-3, mod);

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);

    solve();

    return 0;
}
#include<bits/stdc++.h>
#define ll long long
using namespace std;

ll xorr[1200020];
ll a[300005];

int query(int at, int L, int R, int l, int r){
    if(L>r || R<l)return 0;

    if(l<=L and r>=R)return xorr[at];

    int mid = (L+R)/2;

    return query(at*2,L,mid,l,r)^query(at*2+1,mid+1,R,l,r);
}

void update(int at, int L, int R, int pos, ll u ){
    if(L>pos || R<pos)return ;

    if(L==R){
        xorr[at]^=u;
        return ;
    }

    int mid = (L+R)/2;
    update(at*2,L,mid,pos,u);
    update(at*2+1,mid+1,R,pos,u);
    xorr[at] = xorr[at*2]^xorr[at*2+1];
}

ll build(int at , int L, int R){

    if(L==R){
        xorr[at]=a[L];
        return xorr[at];
    }
    int mid = (L+R)/2;
    ll u = build(at*2,L,mid);
    ll v = build(at*2+1,mid+1,R);

    xorr[at] = u^v;
    return xorr[at];
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    build(1,1,n);


    for(int i=0;i<q;i++){
        int type ;
        cin>>type;

        if(type==1){
            int x,y;
            cin>>x>>y;
            update(1,1,n,x,y);
        }
        else{
            int L,R;
            cin>>L>>R;
            cout<<query(1,1,n,L,R)<<"\n";
        }
    }

}
