#include <bits/stdc++.h>
using namespace std;
int n, q, a[400005];
pair<pair<int, int>, pair<int, int> > b[200005];
long long z[200005], t[400005], d[400005];
vector<int> p[328], o;
inline void inc(int l, int r) {
  int l0 = l, r0 = r;
  while (l <= n) {
    d[l]++;
    t[l] -= l0 - 1;
    l |= (l + 1);
  }
  while (r <= n) {
    d[r]--;
    t[r] += r0;
    r |= (r + 1);
  }
}
inline long long que(int p) {
  long long x = 0, y = 0, p0 = p;
  while (p > 0) {
    x += d[p];
    y += t[p];
    p = (p & (p + 1)) - 1;
  }
  return x * p0 + y;
}
inline long long po(long long a, long long b) {
  long long c = 1;
  while (b) {
    if (b & 1) c = c * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return c;
}
int main() {
  ios::sync_with_stdio(false);
  for (int i = 1; i <= 300; i++) {
    int j = i;
    while (j > 1) {
      for (int k = 2; k <= i; k++)
        if (j % k == 0) {
          j /= k;
          p[i].push_back(k);
          break;
        }
    }
    if (p[i].size() == 1) o.push_back(i);
  }
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < q; i++) {
    z[i] = 1;
    int l, r, x = 0;
    string ss;
    cin >> ss >> l >> r;
    if (ss[0] == 'M') cin >> x;
    b[i] = {{ss[0] == 'T', x}, {l, r}};
  }
  for (int x : o) {
    for (int i = 1; i <= n; i++)
      for (int j : p[a[i]])
        if (j == x) inc(i, i);
    for (int i = 0; i < q; i++) {
      int l = b[i].second.first, r = b[i].second.second, y = b[i].first.second;
      if (b[i].first.first) {
        long long u = que(r), v = que(l - 1);
        if (u != v)
          z[i] = z[i] * po(x, (u - v - 1)) % 1000000007 * (x - 1) % 1000000007;
      } else
        for (int j : p[y])
          if (j == x) inc(l, r);
    }
    for (int i = 1; i <= n; i++) t[i] = d[i] = 0;
  }
  for (int i = 0; i < q; i++)
    if (b[i].first.first) cout << z[i] << '\n';
}
