#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') (c == '-') && (f = -1), c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const long long mod = 1e9 + 7;
int vis[310], cnt;
long long a[400010], p[300], inv[300];
int n = read(), m = read();
struct tree {
  int l, r;
  long long mul, tag, bit, tbit;
  tree() { mul = 1, tag = 1, bit = 0, tbit = 0; }
} t[400010 << 2];
void pushup(int rt) {
  t[rt].mul = t[(rt << 1)].mul * t[(rt << 1 | 1)].mul % mod;
  t[rt].bit = t[(rt << 1)].bit | t[(rt << 1 | 1)].bit;
}
void build(int l, int r, int rt) {
  t[rt].l = l;
  t[rt].r = r;
  t[rt].tag = 1;
  if (l == r) {
    t[rt].mul = a[l] % mod;
    long long qwq = a[l];
    for (long long i = 0; qwq != 1 && i < cnt; ++i)
      if (qwq % p[i] == 0) {
        t[rt].bit |= (1ll << i);
        while (qwq % p[i] == 0) qwq /= p[i];
      }
    return;
  }
  build(l, ((l + r) >> 1), (rt << 1));
  build(((l + r) >> 1) + 1, r, (rt << 1 | 1));
  pushup(rt);
}
long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
void pushdown(int ln, int rn, int rt) {
  if (t[rt].tag != 1 && t[rt].tbit != 0) {
    long long x = t[rt].tag;
    t[rt].tag = 1;
    t[(rt << 1)].tag *= x;
    t[(rt << 1 | 1)].tag *= x;
    t[(rt << 1)].tag %= mod;
    t[(rt << 1 | 1)].tag %= mod;
    t[(rt << 1)].mul = t[(rt << 1)].mul * power(x, ln) % mod;
    t[(rt << 1 | 1)].mul = t[(rt << 1 | 1)].mul * power(x, rn) % mod;
    t[(rt << 1)].tbit |= t[rt].tbit, t[(rt << 1 | 1)].tbit |= t[rt].tbit;
    t[(rt << 1)].bit |= t[rt].tbit;
    t[(rt << 1 | 1)].bit |= t[rt].tbit;
    t[rt].tbit = 0;
  }
}
void upd(int L, int R, long long c, int rt) {
  if (L <= (t[rt].l) && (t[rt].r) <= R) {
    t[rt].mul = t[rt].mul * power(c, (t[rt].r) - (t[rt].l) + 1) % mod;
    t[rt].tag = t[rt].tag * c % mod;
    for (long long i = 0; i < cnt && c != 1; ++i)
      if (c % p[i] == 0) {
        t[rt].bit |= (1ll << i);
        t[rt].tbit |= (1ll << i);
        while (c % p[i] == 0) c /= p[i];
      }
    return;
  }
  pushdown((((t[rt].l) + (t[rt].r)) >> 1) - (t[rt].l) + 1,
           (t[rt].r) - (((t[rt].l) + (t[rt].r)) >> 1), rt);
  if (L <= (((t[rt].l) + (t[rt].r)) >> 1)) upd(L, R, c, (rt << 1));
  if (R > (((t[rt].l) + (t[rt].r)) >> 1)) upd(L, R, c, (rt << 1 | 1));
  pushup(rt);
}
long long query(int L, int R, int rt) {
  long long ans = 1;
  if (L <= (t[rt].l) && (t[rt].r) <= R) return t[rt].mul % mod;
  pushdown((((t[rt].l) + (t[rt].r)) >> 1) - (t[rt].l) + 1,
           (t[rt].r) - (((t[rt].l) + (t[rt].r)) >> 1), rt);
  if (L <= (((t[rt].l) + (t[rt].r)) >> 1))
    ans = ans * query(L, R, (rt << 1)) % mod;
  if (R > (((t[rt].l) + (t[rt].r)) >> 1))
    ans = ans * query(L, R, (rt << 1 | 1)) % mod;
  return ans % mod;
}
long long querybit(int L, int R, int rt) {
  long long ans = 0;
  if (L <= (t[rt].l) && (t[rt].r) <= R) return t[rt].bit;
  pushdown((((t[rt].l) + (t[rt].r)) >> 1) - (t[rt].l) + 1,
           (t[rt].r) - (((t[rt].l) + (t[rt].r)) >> 1), rt);
  if (L <= (((t[rt].l) + (t[rt].r)) >> 1)) ans |= querybit(L, R, (rt << 1));
  if (R > (((t[rt].l) + (t[rt].r)) >> 1)) ans |= querybit(L, R, (rt << 1 | 1));
  return ans;
}
void init(int n) {
  for (int i = 2; i <= n; ++i) {
    if (!vis[i]) p[cnt] = i, inv[cnt] = power(p[cnt], mod - 2), ++cnt;
    for (int j = 0; j < cnt && i * p[j] <= n; ++j) {
      vis[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
}
int main() {
  init(300);
  for (int i = 1; i <= n; ++i) (a[i] = read());
  build(1, n, 1);
  while (m--) {
    char c[10];
    scanf("%s", c);
    int l = read(), r = read();
    if (c[0] == 'M') {
      long long x = read();
      upd(l, r, x, 1);
    } else {
      long long ans = query(l, r, 1), f = querybit(l, r, 1);
      for (long long i = 0; i < 63; ++i)
        if (f & (1ll << i))
          ans = (long long)ans * (p[i] - 1) % mod * inv[i] % mod;
      printf("%lld\n", ans % mod);
    }
  }
}
