#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long LL;
const int MOD = 1e9+7, M = 300;
typedef pair<LL, LL> PLL;
struct Node {
int l, r;
LL pi, exist;
LL tag1, tag2;
};
vector<Node> tr;
unordered_map<int, int> pos;
vector<int> primes;
int n, q;
LL qmi(LL a, LL b) {
LL res = 1;
while(b) {
if(b & 1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
void init() {
vector<bool> vis(M + 1);
for(int i = 2; i <= M; i ++) {
if(!vis[i]) primes.push_back(i);
for(int j = 0; primes[j] * i <= M; j ++) {
vis[primes[j] * i] = true;
if(i % primes[j] == 0) break;
}
}
for(int i = 0; i < primes.size(); i ++) pos[primes[i]] = i;
}
void build(int u, int l, int r) {
tr[u] = {l, r, 1, 0, 1, 0};
if(l != r) {
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
}
}
void pushup(int u) {
tr[u].pi = tr[u << 1].pi * tr[u << 1 | 1].pi % MOD;
tr[u].exist = tr[u << 1].exist | tr[u << 1 | 1].exist;
}
void pushdown(int u) {
if(tr[u].tag1 != 1) {
tr[u << 1].pi = tr[u << 1].pi * qmi(tr[u].tag1, (tr[u << 1].r - tr[u << 1].l + 1)) % MOD;
tr[u << 1 | 1].pi = tr[u << 1 | 1].pi * qmi(tr[u].tag1, tr[u << 1 | 1].r - tr[u << 1 | 1].l + 1) % MOD;
tr[u << 1].tag1 = tr[u << 1].tag1 * tr[u].tag1 % MOD;
tr[u << 1 | 1].tag1 = tr[u << 1 | 1].tag1 * tr[u].tag1 % MOD;
tr[u].tag1 = 1;
}
if(tr[u].tag2) {
tr[u << 1].exist |= tr[u].tag2;
tr[u << 1 | 1].exist |= tr[u].tag2;
tr[u << 1].tag2 |= tr[u].tag2;
tr[u << 1 | 1].tag2 |= tr[u].tag2;
tr[u].tag2 = 0;
}
}
void modify(int u, int l, int r, LL x, LL primex) {
if(l <= tr[u].l && r >= tr[u].r) {
tr[u].pi = tr[u].pi * qmi(x, tr[u].r - tr[u].l + 1) % MOD;
tr[u].exist |= primex;
tr[u].tag1 = tr[u].tag1 * x % MOD;
tr[u].tag2 |= primex;
return;
}
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid) modify(u << 1, l, r, x, primex);
if(r > mid) modify(u << 1 | 1, l, r, x, primex);
pushup(u);
}
LL cal(LL pi, LL exist) {
LL res = pi;
for(int i = 0; i < primes.size(); i ++) {
if(exist >> i & 1) {
res = res * (primes[i] - 1) % MOD * qmi(primes[i], MOD - 2) % MOD;
}
}
return res % MOD;
}
PLL query(int u, int l, int r) {
if(l <= tr[u].l && r >= tr[u].r) {
return {tr[u].pi, tr[u].exist};
}
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
PLL res = {1ll, 0ll};
if(l <= mid) {
PLL resl = query(u << 1, l, r);
res.first = res.first * resl.first % MOD;
res.second |= resl.second;
}
if(r > mid) {
PLL resr = query(u << 1 | 1, l, r);
res.first = res.first * resr.first % MOD;
res.second |= resr.second;
}
return res;
}
LL getExist(LL x) {
LL res = 0;
for(int i = 2; i <= x / i; i ++) {
while(x % i == 0) {
res |= 1ll << pos[i];
x /= i;
}
}
if(x > 1) {
res |= 1ll << pos[x];
}
return res;
}
int main() {
init();
scanf("%d%d", &n, &q);
tr.resize(4 * n);
build(1, 1, n);
for(int i = 1; i <= n; i ++) {
LL a;
scanf("%lld", &a);
modify(1, i, i, a, getExist(a));
}
char op[10];
for(int i = 0; i < q; i ++) {
scanf("%s", op);
if(op[0] == 'Q') {
int l, r;
scanf("%d%d", &l, &r);
PLL res = query(1, l, r);
printf("%lld\n", cal(res.first, res.second));
} else {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
modify(1, l, r, x, getExist(x));
}
}
return 0;
}