#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void chkmin(T &x, T y) {
  if (y < x) x = y;
}
template <typename T>
inline void chkmax(T &x, T y) {
  if (y > x) x = y;
}
template <typename T>
inline T add(T x, T y) {
  return (x + y) % 1000000007;
}
template <typename T>
inline T mul(T x, T y) {
  return 1LL * x * y % 1000000007;
}
template <typename T>
inline T qp(T x, T n) {
  T ans = 1;
  do {
    if (n & 1) ans = mul(ans, x);
    x = mul(x, x);
  } while (n >>= 1);
  return ans;
}
const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
inline long long read() {
  long long x = 0;
  int f = 1,
      c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos);
  for (; !isdigit(c);
       c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos))
    if (c == '-') f = -f;
  for (; isdigit(c);
       c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos))
    x = (x << 3) + (x << 1) + (c ^ 48);
  return x * f;
}
const int N = 1 << 19;
const int B = 450;
int p[100], invp[100], psz;
long long msk[305];
int n, q;
int pwB[305];
struct Node {
  int a;
  long long b;
};
Node a[N], b[N / B], c[N / B];
int main() {
  for (int i = 2; i <= 300; ++i) {
    bool ok = 1;
    for (int j = 2; j * j <= i; ++j)
      if (i % j == 0) ok = 0;
    if (ok) p[psz++] = i;
  }
  for (int i = 0; i < (int)(psz); ++i) invp[i] = qp(p[i], 1000000007 - 2);
  for (int i = 1; i <= 300; ++i) pwB[i] = qp(i, B);
  for (int i = 1; i <= 300; ++i)
    for (int j = 0; j < (int)(psz); ++j)
      if (i % p[j] == 0) msk[i] |= 1LL << j;
  n = read(), q = read();
  for (int i = 0; i < (int)(n); ++i) a[i].a = read();
  for (int i = 0; i < (int)(n); ++i) a[i].b = msk[a[i].a];
  for (int i = 0; i < (int)(n); ++i) b[i / B].a = 1;
  for (int i = 0; i < (int)(n); ++i) c[i / B].a = 1;
  for (int i = 0; i < (int)(n); ++i) c[i / B].a = mul(c[i / B].a, a[i].a);
  for (int i = 0; i < (int)(n); ++i) c[i / B].b |= a[i].b;
  while (q--) {
    char tp =
        (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos);
    int l = read() - 1, r = read();
    if (tp == 'T') {
      int ans = 1;
      long long msk = 0;
      while (l < r && l % B) {
        ans = mul(ans, mul(a[l].a, b[l / B].a));
        msk |= a[l].b | b[l / B].b;
        ++l;
      }
      while (l < r && r % B) {
        --r;
        ans = mul(ans, mul(a[r].a, b[r / B].a));
        msk |= a[r].b | b[r / B].b;
      }
      while (l < r) {
        ans = mul(ans, c[l / B].a);
        msk |= c[l / B].b;
        l += B;
      }
      for (int j = 0; j < (int)(psz); ++j)
        if (msk & 1LL << j) ans = mul(ans, mul(invp[j], p[j] - 1));
      printf("%d\n", ans);
    }
    if (tp == 'M') {
      int x = read();
      while (l < r && l % B) {
        a[l].a = mul(a[l].a, x);
        a[l].b |= msk[x];
        c[l / B].a = mul(c[l / B].a, x);
        c[l / B].b |= msk[x];
        ++l;
      }
      while (l < r && r % B) {
        --r;
        a[r].a = mul(a[r].a, x);
        a[r].b |= msk[x];
        c[r / B].a = mul(c[r / B].a, x);
        c[r / B].b |= msk[x];
      }
      while (l < r) {
        b[l / B].a = mul(b[l / B].a, x);
        b[l / B].b |= msk[x];
        c[l / B].a = mul(c[l / B].a, pwB[x]);
        c[l / B].b |= msk[x];
        l += B;
      }
    }
  }
  return 0;
}
