#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
struct pii
{
ll a, b;
pii() {};
pii(ll A, ll B) {a = A, b = B;}
const pii operator * (const int &c) const {return pii((a * c) % mod, (b * c) % mod);}
const pii operator + (const pii &c) const {return pii((a + c.a) % mod, (b + c.b) % mod);}
};
struct node
{
pii a, b;
node() {a = pii(1, 0), b = pii(0, 1);}
node(pii A, pii B) {a = A, b = B;}
const node operator + (const node &c) const {return node((c.a * a.a) + (c.b * a.b), (c.a * b.a) + (c.b * b.b));}
pii val(pii t)
{
return pii(((a.a * t.a) % mod + (a.b * t.b) % mod) % mod, ((b.a * t.a) % mod + (b.b * t.b) % mod) % mod);
}
void swap()
{
pii tem = a;
a = b;
b = tem;
}
} va[350];
bool vis[350];
int n, q;
string s;
int len;
int main(int argc, char const *argv[])
{
cin >> n >> q >> s;
len = (int) sqrt (n + .0) + 1;
for (int i = 0; i < n; i++)
{
if (s[i] == 'A')
{
va[i / len] = (node(pii(1, 1), pii(0, 1)) + va[i / len]);
}
else
{
va[i / len] = (node(pii(1, 0), pii(1, 1)) + va[i / len]);
}
}
ll l, r, t, aa, bb;
while (q--)
{
cin >> t;
if (t == 2)
{
cin >> l >> r >> aa >> bb;
l--; r--;
node sum(pii(1, 0), pii(0, 1));
for (int i = l; i <= r; )
if (i % len == 0 && i + len - 1 <= r) {
sum = va[i / len] + sum;
i += len;
}
else {
if (vis[i / len] == 0)
{
if (s[i] == 'A')
sum = node(pii(1, 1), pii(0, 1)) + sum;
else sum = node(pii(1, 0), pii(1, 1)) + sum;
}
else
{
if (s[i] == 'B')
sum = node(pii(1, 1), pii(0, 1)) + sum;
else sum = node(pii(1, 0), pii(1, 1)) + sum;
}
++i;
}
cout << sum.val(pii(aa, bb)).a << ' ' << sum.val(pii(aa, bb)).b << endl;
}
else
{
cin >> l >> r;
l--; r--;
int st = -1, en = -1;
for (int i = l; i <= r; )
if (i % len == 0 && i + len - 1 <= r) {
va[i / len].swap();
vis[i / len] = !vis[i / len];
i += len;
}
else {
if (st == -1)st = i / len;
en = i / len;
if (s[i] == 'A')
s[i] = 'B';
else s[i] = 'A';
++i;
}
if (st != -1)
{
va[st / len] = node(pii(1, 0), pii(0, 1));
for (int i = st; i < st + len && i < n; i++)
{
if (s[i] == 'A')
{
va[i / len] = (node(pii(1, 1), pii(0, 1)) + va[i / len]);
}
else
{
va[i / len] = (node(pii(1, 0), pii(1, 1)) + va[i / len]);
}
}
if (vis[st / len])va[st / len].swap();
}
if (en != -1)
{
va[en / len] = node(pii(1, 0), pii(0, 1));
for (int i = en; i < en + len && i < n; i++)
{
if (s[i] == 'A')
{
va[i / len] = (node(pii(1, 1), pii(0, 1)) + va[i / len]);
}
else
{
va[i / len] = (node(pii(1, 0), pii(1, 1)) + va[i / len]);
}
}
if (vis[en / len])va[en / len].swap();
}
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKIApjb25zdCBsb25nIGxvbmcgbW9kID0gMTAwMDAwMDAwNzsKI2RlZmluZSBsbCBsb25nIGxvbmcKc3RydWN0IHBpaQp7CglsbCBhLCBiOwoJcGlpKCkge307CglwaWkobGwgQSwgbGwgQikge2EgPSBBLCBiID0gQjt9Cgljb25zdCBwaWkgb3BlcmF0b3IgKiAoY29uc3QgaW50ICZjKSBjb25zdCB7cmV0dXJuIHBpaSgoYSAqIGMpICUgbW9kLCAoYiAqIGMpICUgbW9kKTt9Cgljb25zdCBwaWkgb3BlcmF0b3IgKyAoY29uc3QgcGlpICZjKSBjb25zdCB7cmV0dXJuIHBpaSgoYSArIGMuYSkgJSBtb2QsIChiICsgYy5iKSAlIG1vZCk7fQp9OwpzdHJ1Y3Qgbm9kZQp7CglwaWkgYSwgYjsKCW5vZGUoKSB7YSA9IHBpaSgxLCAwKSwgYiA9IHBpaSgwLCAxKTt9Cglub2RlKHBpaSBBLCBwaWkgQikge2EgPSBBLCBiID0gQjt9Cgljb25zdC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