#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[2000005], b[2000005], tree[4*300000];

void build(ll node, ll lo, ll hi)
{
    if(lo==hi)
    {
        tree[node] =a[lo];
        return;
    }

    ll left = node*2, right = left+1;
    ll mid = (lo+hi)/2;
    build(left, lo, mid);
    build(right, mid+1, hi);

    tree[node] = tree[left]^tree[right];
}

void update(ll node, ll lo, ll hi, ll i, ll val)
{
    if(lo>i||hi<i)
        return;
    if(lo==i&&hi==i)
    {
        tree[node]^=val;
        return;
    }
    ll left = node*2, right = left+1;
    ll mid = (lo+hi)/2;

    update(left, lo,mid, i,val);
    update(right, mid+1, hi, i,val);

    tree[node] = tree[left]^tree[right];


}

ll  query(ll node, ll lo, ll hi, ll i, ll j)
{
    if(lo>j||hi<i)
        return 0LL;
    if(lo>=i&&hi<=j)
    {
        return tree[node];
    }
    ll left = node*2, right = left+1;
    ll mid = (lo+hi)/2;
    ll p = query(left, lo, mid, i,j);
    ll q = query(right, mid+1, hi, i, j);


    return p^q;
}
int main()
{

    ll  n, q;
    cin >> n >> q;
    for(ll i=1;i<=n;i++) cin >> a[i];
    build(1,1,n);

    while(q--)
    {
        ll t, x, y;
        scanf("%lld%lld%lld",&t,&x,&y);
        if(t==1)
        {
            update(1,1,n,x,y);
        }
        else
        {
            ll ans = query(1,1,n,x,y);
            printf("%lld\n",ans);
        }
    }

}

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ri register int
#define ll long long
#define ui unsigned int
il ll read(){
    bool f=true;ll x=0;
    register char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=false;ch=getchar();}
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    if(f) return x;
    return ~(--x);
}
il int read(char *s){
    int len=0;
    register char ch=getchar();
    while(ch==' '||ch=='\n') ch=getchar();
    while(ch!=' '&&ch!='\n'&&ch!=EOF) s[++len]=ch,ch=getchar();
    return len;
}
il void write(const ll &x){if(x>9) write(x/10);putchar(x%10+'0');}
il void print(const ll &x) {x<0?putchar('-'),write(~(x-1)):write(x);putchar('\n');}
il ll max(const ll &a,const ll &b){return a>b?a:b;}
il ll min(const ll &a,const ll &b){return a<b?a:b;}ll n;
string c;
const ll mod =1e9+7;
il ll ksm(ll d,ll t){
    ll res=1;
    for(;t;t>>=1,d=d*d%mod)
        if(t&1) res=res*d%mod;
    return res;
}
struct hmap{
    static const int P=2e6+3,M=3e6+10;
    int hed[M],nxt[M],cnt;ll val[M];ll as[M];
    bool count(ll x){
        int c=hed[x%P];
        while(c){
            if(val[c]==x) return 1;
            c=nxt[c];
        }return 0;
    }
    ll& operator [](ll x){
        int c=hed[x%P];
        while(c){
            if(val[c]==x) return as[c];
            c=nxt[c];
        }
        ++cnt;val[cnt]=x;nxt[cnt]=hed[x%P];hed[x%P]=cnt;
        return as[cnt];
    }
    int size(){return cnt;}
}f;
ll get_f(ll tmp){
    if(f.count(tmp)) return f[tmp]%mod;
    if(tmp&1) return f[tmp]=((get_f(tmp/2+1)*get_f(tmp/2+1)%mod)+(get_f(tmp/2)*get_f(tmp/2)%mod))%mod;
    else return f[tmp]=get_f(tmp/2)*((get_f(tmp/2+1)+get_f(tmp/2-1))%mod)%mod; 
}
int main(){
    n=read();
    c="";
    string t;
    t=getchar(),c=c+t,getchar();
    t=getchar(),c=c+t,getchar();
    t=getchar(),c=c+t,getchar();
    t=getchar(),c=c+t,getchar();
    if(n==2||c=="AAAA"||c=="AAAB"||c=="AABA"||c=="AABB"||c=="ABAB"||c=="ABBB"||c=="BBAB"||c=="BBBB"){
        print(1);
        return 0;
    }
    else if(c=="ABAA"||c=="BABA"||c=="BABB"||c=="BBAA"){
        print(ksm(2,n-3));
        return 0;
    }
    else if(c=="BAAA"||c=="ABBA"||c=="BBBA"||c=="BAAB"){
        f[1]=f[2]=1;
        print(get_f(n-1));
        return 0;
    }
    return 0;
}

/*
1000
B
A
A
A

589888339
*/