#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 7, K = 305, M = 1e9 + 7;
long long mask[K];
bool isp[K];
vector<int> primes;
void pre() {
  fill(isp, isp + K, 1);
  isp[0] = isp[1] = 0;
  int id = 0;
  for (long long i = 2; i < K; i++)
    if (isp[i]) {
      for (long long j = i; j < K; j += i) isp[j] = 0, mask[j] |= (1LL << id);
      ++id;
      primes.push_back(i);
    }
}
int power(int a, int p) {
  if (p == 0) return 1;
  int ans = power(a, p / 2);
  ans = (1LL * ans * ans) % M;
  if (p % 2) ans = (1LL * ans * a) % M;
  return ans;
}
struct Data {
  int product;
  long long mask;
  Data() {
    product = 1;
    mask = 0;
  }
  Data(long long p, long long m) { product = p, mask = m; }
};
Data combine(Data l, Data r, int k = 1) {
  Data ans;
  ans.product = (1LL * l.product * power(r.product, k)) % M;
  ans.mask = l.mask | r.mask;
  return ans;
}
Data tr[4 * N];
Data lz[4 * N];
int a[N];
void build(int u, int st, int en) {
  if (st == en) {
    tr[u] = Data(a[st], mask[a[st]]);
    return;
  }
  int m = (st + en) / 2;
  build(2 * u, st, m);
  build(2 * u + 1, m + 1, en);
  tr[u] = combine(tr[2 * u], tr[2 * u + 1]);
}
void propagate(int u, int st, int en) {
  tr[u] = combine(tr[u], lz[u], en - st + 1);
  if (st != en)
    lz[2 * u] = combine(lz[2 * u], lz[u]),
           lz[2 * u + 1] = combine(lz[2 * u + 1], lz[u]);
  lz[u] = Data();
}
void update(int u, int st, int en, int l, int r, Data d) {
  propagate(u, st, en);
  if (r < st || en < l)
    return;
  else if (l <= st && en <= r)
    lz[u] = combine(lz[u], d), propagate(u, st, en);
  else {
    int m = (st + en) / 2;
    update(2 * u, st, m, l, r, d);
    update(2 * u + 1, m + 1, en, l, r, d);
    tr[u] = combine(tr[2 * u], tr[2 * u + 1]);
  }
}
Data query(int u, int st, int en, int l, int r) {
  propagate(u, st, en);
  if (r < st || en < l)
    return Data();
  else if (l <= st && en <= r)
    return tr[u];
  else {
    int m = (st + en) / 2;
    Data ll = query(2 * u, st, m, l, r);
    Data rr = query(2 * u + 1, m + 1, en, l, r);
    return combine(ll, rr);
  }
}
void print(int u, int st, int en) {
  if (st == en) {
    return;
  }
  int m = (st + en) / 2;
  print(2 * u, st, m);
  print(2 * u + 1, m + 1, en);
  tr[u] = combine(tr[2 * u], tr[2 * u + 1]);
}
int inverse(int a) { return power(a, M - 2); }
int main() {
  pre();
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build(1, 1, n);
  print(1, 1, n);
  while (q--) {
    string s;
    int l, r, x;
    cin >> s >> l >> r;
    if (s[0] == 'M')
      cin >> x, update(1, 1, n, l, r, Data(x, mask[x]));
    else {
      Data qq = query(1, 1, n, l, r);
      int ans = qq.product;
      long long msk = qq.mask;
      int num = 1, denom = 1;
      for (long long i = 0; i < 64; i++)
        if (msk & (1LL << i)) {
          num = (1LL * num * (primes[i] - 1)) % M;
          denom = (1LL * denom * primes[i]) % M;
        }
      ans = (1LL * ans * num) % M;
      ans = (1LL * ans * inverse(denom)) % M;
      cout << ans << "\n";
    }
  }
}
