#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
inline int power(int a, int t) {
  int res = 1;
  while (t) {
    if (t & 1) res = (long long)res * a % 1000000007;
    a = (long long)a * a % 1000000007;
    t >>= 1;
  }
  return res;
}
inline int dec(int a, int b) { return a < b ? a - b + 1000000007 : a - b; }
int pr[303], a[400003], tag1[400003 << 2], mul[400003 << 2], inv[303];
bool vis[303];
unsigned long long st[303], s[400003 << 2], tag2[400003 << 2];
char str[233];
int n, q, cnt;
inline void sieve(int n) {
  for (register int i = 2; i <= n; ++i) {
    if (!vis[i]) pr[++cnt] = i;
    for (register int j = 1; j <= cnt; ++j) {
      if (i * pr[j] > n) break;
      vis[i * pr[j]] = true;
      if (i % pr[j] == 0) break;
    }
  }
  inv[1] = 1;
  for (register int i = 2; i <= n; ++i)
    inv[i] = (long long)(1000000007 - 1000000007 / i) * inv[1000000007 % i] %
             1000000007;
}
void pushup(int u) {
  s[u] = s[(u << 1)] | s[(u << 1 | 1)];
  mul[u] = (long long)mul[(u << 1)] * mul[(u << 1 | 1)] % 1000000007;
}
inline void pushdown(int u, int l, int r) {
  if (tag1[u] != 1) {
    tag1[(u << 1)] = (long long)tag1[(u << 1)] * tag1[u] % 1000000007;
    tag1[(u << 1 | 1)] = (long long)tag1[(u << 1 | 1)] * tag1[u] % 1000000007;
    mul[(u << 1)] = (long long)mul[(u << 1)] *
                    power(tag1[u], ((l + r) >> 1) - l + 1) % 1000000007;
    mul[(u << 1 | 1)] = (long long)mul[(u << 1 | 1)] *
                        power(tag1[u], r - ((l + r) >> 1)) % 1000000007;
    tag1[u] = 1;
  }
  if (tag2[u]) {
    tag2[(u << 1)] |= tag2[u], tag2[(u << 1 | 1)] |= tag2[u];
    s[(u << 1)] |= tag2[u], s[(u << 1 | 1)] |= tag2[u];
    tag2[u] = 0;
  }
}
void build(int l, int r, int u) {
  if (l == r) {
    s[u] = st[a[l]];
    mul[u] = a[l];
    return;
  }
  build(l, ((l + r) >> 1), (u << 1));
  build(((l + r) >> 1) + 1, r, (u << 1 | 1));
  pushup(u);
}
void modify(int nl, int nr, int l, int r, int u, int k) {
  if (nl <= l && r <= nr) {
    tag1[u] = (long long)tag1[u] * k % 1000000007;
    tag2[u] |= st[k];
    s[u] |= st[k];
    mul[u] = (long long)mul[u] * power(k, r - l + 1) % 1000000007;
    return;
  }
  pushdown(u, l, r);
  if (nl <= ((l + r) >> 1)) modify(nl, nr, l, ((l + r) >> 1), (u << 1), k);
  if (nr > ((l + r) >> 1))
    modify(nl, nr, ((l + r) >> 1) + 1, r, (u << 1 | 1), k);
  pushup(u);
}
int qmul(int nl, int nr, int l, int r, int u) {
  if (nl <= l && r <= nr) return mul[u];
  pushdown(u, l, r);
  int res = 1;
  if (nl <= ((l + r) >> 1))
    res =
        (long long)res * qmul(nl, nr, l, ((l + r) >> 1), (u << 1)) % 1000000007;
  if (nr > ((l + r) >> 1))
    res = (long long)res * qmul(nl, nr, ((l + r) >> 1) + 1, r, (u << 1 | 1)) %
          1000000007;
  return res;
}
unsigned long long qset(int nl, int nr, int l, int r, int u) {
  if (nl <= l && r <= nr) return s[u];
  pushdown(u, l, r);
  unsigned long long res = 0;
  if (nl <= ((l + r) >> 1)) res |= qset(nl, nr, l, ((l + r) >> 1), (u << 1));
  if (nr > ((l + r) >> 1))
    res |= qset(nl, nr, ((l + r) >> 1) + 1, r, (u << 1 | 1));
  return res;
}
int main() {
  for (register int i = 0; i < (400003 << 2); ++i) tag1[i] = 1;
  int l, r, k, pt, ans;
  unsigned long long tmp;
  sieve(300);
  read(n), read(q);
  for (register int i = 1; i <= n; ++i) read(a[i]);
  for (register int i = 1; i <= 300; ++i)
    for (register int j = 1; j <= cnt; ++j)
      if (i % pr[j] == 0) st[i] |= 1ull << j;
  build(1, n, 1);
  while (q--) {
    pt = 0;
    char c = getchar();
    while (c < 'A' || c > 'Z') c = getchar();
    while (c >= 'A' && c <= 'Z') {
      str[++pt] = c;
      c = getchar();
    }
    read(l), read(r);
    if (str[1] == 'T') {
      ans = qmul(l, r, 1, n, 1);
      tmp = qset(l, r, 1, n, 1);
      for (register int i = 1; i <= cnt; ++i) {
        if (!((tmp >> i) & 1)) continue;
        ans = (long long)ans * dec(1, inv[pr[i]]) % 1000000007;
      }
      print(ans);
      putchar('\n');
    } else {
      read(k);
      modify(l, r, 1, n, 1, k);
    }
  }
  return 0;
}
