#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  char c;
  do {
    c = getchar();
  } while (!isdigit(c));
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (isdigit(c));
  return x;
}
int opt() {
  char c;
  do {
    c = getchar();
  } while (c != 'M' && c != 'T');
  return c == 'M';
}
const long long mod = (long long)(1e9) + 7LL;
const int N = 400000 + 10;
const int P = 62 + 3;
const int V = 300 + 10;
long long qpow(long long a, long long p) {
  if (p == 0) return (a % mod > 0);
  long long r = qpow(a, p >> 1);
  r = r * r % mod;
  return (p & 1) ? (r * a % mod) : r;
}
int prime[P], cnt;
long long ph[P];
bitset<P> has[V];
int isprime(int x) {
  if (x < 2) return 0;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
int n, q, a[N];
namespace Tmul {
long long mul[N << 2], tag[N << 2];
void build(int o, int l, int r) {
  tag[o] = 1;
  if (l == r) {
    mul[o] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build((o << 1), l, mid);
  build(((o << 1) | 1), mid + 1, r);
  mul[o] = mul[(o << 1)] * mul[((o << 1) | 1)] % mod;
}
int inter(int l, int r, int a, int b) {
  l = max(l, a);
  r = min(r, b);
  return max(r - l + 1, 0);
}
void update(int o, int L, int R, int l, int r, long long x) {
  if (L > r || R < l) return;
  mul[o] = mul[o] * qpow(x, inter(L, R, l, r)) % mod;
  if (l <= L && R <= r) {
    tag[o] = tag[o] * x % mod;
    return;
  }
  int mid = (L + R) >> 1;
  update((o << 1), L, mid, l, r, x);
  update(((o << 1) | 1), mid + 1, R, l, r, x);
}
long long query(int o, int L, int R, int l, int r, long long m = 1) {
  if (L > r || R < l) return 1;
  if (l <= L && R <= r) return mul[o] * qpow(m, R - L + 1) % mod;
  m = m * tag[o] % mod;
  int mid = (L + R) >> 1;
  return query((o << 1), L, mid, l, r, m) *
         query(((o << 1) | 1), mid + 1, R, l, r, m) % mod;
}
}  // namespace Tmul
namespace Tfac {
bitset<P> fs[N << 2], tag[N << 2];
inline void pushup(int o) { fs[o] = fs[(o << 1)] | fs[((o << 1) | 1)]; }
void pushdown(int o) {
  if (tag[o].any()) {
    fs[(o << 1)] |= tag[o];
    fs[((o << 1) | 1)] |= tag[o];
    tag[(o << 1)] |= tag[o];
    tag[((o << 1) | 1)] |= tag[o];
    tag[o].reset();
  }
  assert(!tag[o].any());
}
void build(int o, int l, int r) {
  tag[o].reset();
  if (l == r) {
    fs[o] = has[a[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build((o << 1), l, mid);
  build(((o << 1) | 1), mid + 1, r);
  pushup(o);
}
void update(int o, int L, int R, int l, int r, const bitset<P> &x) {
  if (L > r || R < l) return;
  if (l <= L && R <= r) {
    tag[o] |= x;
    fs[o] |= x;
    return;
  }
  pushdown(o);
  int mid = (L + R) >> 1;
  update((o << 1), L, mid, l, r, x);
  update(((o << 1) | 1), mid + 1, R, l, r, x);
  pushup(o);
}
bitset<P> query(int o, int L, int R, int l, int r) {
  if (L > r || R < l) return bitset<P>(0);
  if (l <= L && R <= r) return fs[o];
  pushdown(o);
  int mid = (L + R) >> 1;
  return query((o << 1), L, mid, l, r) |
         query(((o << 1) | 1), mid + 1, R, l, r);
}
}  // namespace Tfac
int main() {
  for (int i = 1; i <= 300; i++) {
    has[i] = bitset<P>(0);
    if (isprime(i)) {
      has[i][cnt] = 1;
      ph[cnt] = 1LL * (i - 1) * qpow(i, mod - 2) % mod;
      prime[cnt++] = i;
    } else
      for (int j = 0; j < cnt; j++) has[i][j] = (i % prime[j] == 0);
  }
  n = read();
  q = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  Tmul::build(1, 1, n);
  Tfac::build(1, 1, n);
  int l, r, x, o;
  long long ans = 0;
  while (q--) {
    o = opt();
    l = read();
    r = read();
    if (o) {
      x = read();
      if (x == 1) continue;
      Tmul::update(1, 1, n, l, r, x);
      Tfac::update(1, 1, n, l, r, has[x]);
    } else {
      ans = Tmul::query(1, 1, n, l, r);
      bitset<P> fs = Tfac::query(1, 1, n, l, r);
      for (int i = 0; i < cnt; i++)
        if (fs[i]) ans = ans * ph[i] % mod;
      printf("%d\n", (int)(ans));
    }
  }
  return 0;
}
