#include <bits/stdc++.h>
using namespace std;
const int mmax = 4e5 + 5;
const long long mod = 1e9 + 7;
int pri[66], vis[305];
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) ret = ret * x % mod;
  return ret;
}
long long inv(long long x) { return ksm(x, mod - 2); }
void init() {
  memset(pri, 0, sizeof(pri));
  for (int i = 2; i <= 300; i++) {
    if (!vis[i]) {
      pri[++pri[0]] = i;
    }
    for (int j = 1; j <= pri[0] && i * pri[j] <= 300; j++) {
      vis[i * pri[j]] = true;
      if (i % pri[j] == 0) break;
    }
  }
}
int n, flag = 0, flag1 = 0;
long long a[mmax * 4 + 5];
long long exist[mmax * 4 + 5];
long long mu[mmax * 4 + 5];
long long priex[mmax * 4 + 5];
void build(int k, int l, int r) {
  mu[k] = 1;
  exist[k] = 0;
  if (l == r) {
    scanf("%I64d", &a[k]);
    for (int i = 1; i <= pri[0]; i++)
      if (a[k] % pri[i] == 0) exist[k] |= (1ll << (i - 1));
    return;
  }
  int mid = (l + r) >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  a[k] = a[k << 1] * a[k << 1 | 1] % mod;
  exist[k] = exist[k << 1] | exist[k << 1 | 1];
}
void Or(int k, long long s) {
  exist[k] |= s;
  priex[k] |= s;
}
void Mul(int k, int l, int r, long long mul) {
  mu[k] = mu[k] * mul % mod;
  a[k] = a[k] * ksm(mul, r - l + 1) % mod;
}
void pushdown(int k, int l, int r) {
  int mid = (l + r) >> 1;
  if (mu[k] != 1) {
    Mul(k << 1, l, mid, mu[k]);
    Mul(k << 1 | 1, mid + 1, r, mu[k]);
  }
  Or(k << 1, priex[k]);
  Or(k << 1 | 1, priex[k]);
  mu[k] = 1;
  priex[k] = 0;
}
pair<long long, long long> query(int k, int l, int r, int x, int y) {
  if (x <= l && y >= r) return make_pair(a[k], exist[k]);
  pushdown(k, l, r);
  int mid = (l + r) >> 1;
  pair<long long, long long> L, R, ans(1, 0);
  if (x <= mid)
    L = query(k << 1, l, mid, x, y), ans.first = ans.first * L.first % mod,
    ans.second |= L.second;
  if (y > mid)
    R = query(k << 1 | 1, mid + 1, r, x, y),
    ans.first = ans.first * R.first % mod, ans.second |= R.second;
  return ans;
}
long long query(int l, int r) {
  pair<long long, long long> ans = query(1, 1, n, l, r);
  for (int i = 1; i <= pri[0]; i++)
    if (ans.second & (1ll << (i - 1)))
      ans.first = ans.first * (pri[i] - 1) % mod * inv(pri[i]) % mod;
  return ans.first;
}
void updata(int k, int l, int r, int x, int y, long long mul, long long s) {
  int mid = (l + r) >> 1;
  if (x <= l && r <= y) {
    Mul(k, l, r, mul);
    Or(k, s);
    return;
  }
  pushdown(k, l, r);
  if (x <= mid) updata(k << 1, l, mid, x, y, mul, s);
  if (y > mid) updata(k << 1 | 1, mid + 1, r, x, y, mul, s);
  a[k] = a[k << 1] * a[k << 1 | 1] % mod;
  exist[k] = exist[k << 1] | exist[k << 1 | 1];
}
void modify(int l, int r, int x) {
  long long s = 0;
  for (int i = 1; i <= pri[0]; i++)
    if (x % pri[i] == 0) s |= (1ll << (i - 1));
  updata(1, 1, n, l, r, x, s);
}
int main() {
  init();
  char str[10];
  int m, l, r, x;
  read(n, m);
  build(1, 1, n);
  for (int i = 0; i < m; i++) {
    scanf("%s", str);
    if (str[0] == 'T') {
      read(l, r);
      printf("%I64d\n", query(l, r));
    } else {
      read(l, r, x);
      modify(l, r, x);
    }
  }
  return 0;
}
