#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll mod = 1e9+7;
const int maxn = 1e5 + 5;
using matrix = array<ll,4>;
void add(ll& x, ll y) {
if (x>=mod) x%=mod;
if (y>=mod) y%=mod;
x += y;
if (x>=mod) x%=mod;
}
void mul(ll& x, ll y) {
if (x>=mod) x%=mod;
if (y>=mod) y%=mod;
long long tmp = 1ll*x*y;
tmp %= mod;
x = tmp;
}
ll addr(ll x, ll y) {
if (x>=mod) x%=mod;
if (y>=mod) y%=mod;
x += y;
if (x>=mod) x%=mod;
return x;
}
ll mulr(ll x, ll y) {
if (x>=mod) x%=mod;
if (y>=mod) y%=mod;
long long tmp = 1ll*x*y;
tmp %= mod;
return tmp;
}
matrix mul(matrix a, matrix b) {
matrix res;
res[0]=addr(mulr(a[0],b[0]),mulr(a[1],b[2]));
res[1]=addr(mulr(a[0],b[1]),mulr(a[1],b[3]));
res[2]=addr(mulr(a[2],b[0]),mulr(a[3],b[2]));
res[3]=addr(mulr(a[2],b[1]),mulr(a[3],b[3]));
return res;
}
matrix id2() {
return {1,0,0,1};
}
matrix matA() {
// 1 1
// 0 1
return {1,1,0,1};
}
matrix matB() {
// 1 0
// 1 1
return {1,0,1,1};
}
void flip(matrix& M) {
M = {M[3],M[2],M[1],M[0]};
}
int n, q;
string s;
using node = matrix;
node t[4*maxn];
bool o[4*maxn];
node merge(node a, node b) {
return mul(b, a);
}
void build(int v, int tl, int tr) {
if (tl==tr) {
t[v] = s[tl] == 'A' ? matA() : matB();
} else {
int tm=(tl+tr)/2;
build(2*v,tl,tm);
build(2*v+1,tm+1,tr);
t[v] = merge(t[2*v], t[2*v+1]);
}
}
void push(int v) {
if (!o[v]) return;
flip(t[2*v]);
flip(t[2*v+1]);
o[2*v]=!o[2*v];
o[2*v+1]=!o[2*v+1];
o[v]=false;
}
void flip(int v, int tl, int tr, int l, int r) {
if (r<tl || l>tr) {
return;
}
if (l<=tl && tr<=r) {
flip(t[v]);
o[v] = !o[v];
return;
}
int tm=(tl+tr)/2;
push(v);
flip(2*v,tl,tm,l,r);
flip(2*v+1,tm+1,tr,l,r);
t[v]=merge(t[2*v],t[2*v+1]);
}
matrix qry(int v, int tl, int tr, int l, int r) {
if (l>tr || r<tl) {
return id2();
}
if (l<=tl && tr<=r) {
return t[v];
}
int tm=(tl+tr)/2;
push(v);
return mul(qry(2*v+1,tm+1,tr,l,r), qry(2*v,tl,tm,l,r));
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>q;
cin>>s;
s="."+s;
build(1,1,n);
while (q--) {
int typ;
cin>>typ;
if (typ==2) {
int l,r; ll a,b;
cin>>l>>r>>a>>b;
matrix M = qry(1,1,n,l,r);
ll resa = addr(mulr(M[0],a), mulr(M[1],b));
ll resb = addr(mulr(M[2],a), mulr(M[3],b));
cout<<resa<<" "<<resb<<"\n";
}
if (typ==1) {
int l,r;
cin>>l>>r;
flip(1,1,n,l,r);
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKdGVtcGxhdGU8dHlwZW5hbWUgVD4Kdm9pZCBvdXQoVCB4KSB7IGNvdXQgPDwgeCA8PCBlbmRsOyBleGl0KDApOyB9CiNkZWZpbmUgd2F0Y2goeCkgY291dCA8PCAoI3gpIDw8ICIgaXMgIiA8PCAoeCkgPDwgZW5kbAogCiAKIAogCnVzaW5nIGxsID0gbG9uZyBsb25nOwpjb25zdCBsbCBtb2QgPSAxZTkrNzsKY29uc3QgaW50IG1heG4gPSAxZTUgKyA1OwogCiAKdXNpbmcgbWF0cml4ID0gYXJyYXk8bGwsND47CiAKdm9pZCBhZGQobGwmIHgsIGxsIHkpIHsKICAgIGlmICh4Pj1tb2QpIHglPW1vZDsKICAgIGlmICh5Pj1tb2QpIHklPW1vZDsKICAgIHggKz0geTsKICAgIGlmICh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