#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
template <typename T>
inline void in(T &x) {
  register char ch;
  x = 0;
  while (isspace(ch = getchar()))
    ;
  do x = x * 10 + ch - '0';
  while (isdigit(ch = getchar()));
}
const int PS = 300, PL = 305, N = 400000 * 4 + 5;
bool np[PL];
int ps = 0;
long long p[PL], invp[PL];
long long qp(long long a, int b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
void prime_list(int n) {
  for (int i = 2; i <= n; i++) {
    if (!np[i]) {
      p[ps++] = i;
      invp[ps - 1] = qp(i, mod - 2);
    }
    for (int j = i * i; j <= n; j += i) np[j] = true;
  }
}
long long getfac(int x) {
  long long ans = 0;
  for (int i = 0; i < ps; i++)
    if (x % p[i] == 0) ans |= (1LL << i);
  return ans;
}
long long ediv(long long x) {
  long long ans = 1;
  for (int i = 0; i < ps; i++)
    if (x & (1LL << i)) ans = ans * (p[i] - 1) % mod * invp[i] % mod;
  return ans;
}
long long v[N], fac[N], mt[N], ft[N];
inline void upd(int x) {
  v[x] = v[(x << 1)] * v[((x << 1) | 1)] % mod;
  fac[x] = fac[(x << 1)] | fac[((x << 1) | 1)];
}
inline void pd(int x, int llen, int rlen) {
  if (mt[x] != 1) {
    v[(x << 1)] = (v[(x << 1)] * qp(mt[x], llen)) % mod;
    v[((x << 1) | 1)] = v[((x << 1) | 1)] * qp(mt[x], rlen) % mod;
    mt[(x << 1)] = (mt[(x << 1)] * mt[x]) % mod;
    mt[((x << 1) | 1)] = (mt[((x << 1) | 1)] * mt[x]) % mod;
    mt[x] = 1;
  }
  if (ft[x]) {
    fac[(x << 1)] |= ft[x];
    fac[((x << 1) | 1)] |= ft[x];
    ft[(x << 1)] |= ft[x];
    ft[((x << 1) | 1)] |= ft[x];
    ft[x] = 0;
  }
}
void build(int x, int l, int r) {
  mt[x] = 1;
  ft[x] = 0;
  if (l == r) {
    in(v[x]);
    fac[x] = getfac(v[x]);
    return;
  }
  int mid = (l + r) >> 1;
  build((x << 1), l, mid);
  build(((x << 1) | 1), mid + 1, r);
  upd(x);
}
void edit(int x, int l, int r, int a, int b, long long Mul, long long Fac) {
  if (a <= l && b >= r) {
    v[x] = v[x] * qp(Mul, r - l + 1) % mod;
    mt[x] = mt[x] * Mul % mod;
    fac[x] |= Fac;
    ft[x] |= Fac;
    return;
  }
  int mid = (l + r) >> 1;
  pd(x, mid - l + 1, r - mid);
  if (a <= mid) edit((x << 1), l, mid, a, b, Mul, Fac);
  if (b > mid) edit(((x << 1) | 1), mid + 1, r, a, b, Mul, Fac);
  upd(x);
}
pair<long long, long long> query(int x, int l, int r, int a, int b) {
  if (a <= l && b >= r) return make_pair(v[x], fac[x]);
  int mid = (l + r) >> 1;
  pd(x, mid - l + 1, r - mid);
  pair<long long, long long> ans = make_pair(1ll, 0ll), t;
  if (a <= mid) {
    t = query((x << 1), l, mid, a, b);
    ans.first = (ans.first * t.first) % mod;
    ans.second |= t.second;
  }
  if (b > mid) {
    t = query(((x << 1) | 1), mid + 1, r, a, b);
    ans.first = (ans.first * t.first) % mod;
    ans.second |= t.second;
  }
  return ans;
}
int main() {
  prime_list(300);
  int n, q, l, r, x;
  in(n);
  in(q);
  for (int i = 0; i <= n * 4; i++) v[i] = 1;
  build(1, 1, n);
  static char op[30];
  pair<long long, long long> res;
  while (q--) {
    scanf("%s", op);
    in(l);
    in(r);
    if (op[0] == 'M') {
      in(x);
      edit(1, 1, n, l, r, x, getfac(x));
    } else {
      res = query(1, 1, n, l, r);
      printf("%lld\n", res.first * ediv(res.second) % mod);
    }
  }
  return 0;
}
