#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
char cmd[100];
int x, y, z;
const int N = 400005;
bool prime(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (!(x % i)) return 0;
  return 1;
}
long long pow_mod(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) (ans *= a) %= mod;
    (a *= a) %= mod;
    n >>= 1;
  }
  return ans;
}
int n, q, p[66], cnt = 0;
long long inv[66], mul[N << 2], mask[N << 2], flag1[N << 2], flag2[N << 2];
void init(int r, int L, int R) {
  flag1[r] = 1;
  if (L == R) {
    scanf("%I64d", mul + r);
    for (int i = 0; i < cnt; ++i)
      if (!(mul[r] % p[i])) mask[r] |= (1LL << i);
    return;
  }
  int mid = L + R >> 1;
  init(r << 1, L, mid);
  init(r << 1 | 1, mid + 1, R);
  mul[r] = mul[r << 1] * mul[r << 1 | 1] % mod;
  mask[r] = mask[r << 1] | mask[r << 1 | 1];
}
long long getmask(int x) {
  long long ans = 0;
  for (int i = 0; i < cnt; ++i)
    if (!(x % p[i])) ans |= 1LL << i;
  return ans;
}
void down(int r, int L, int mid, int R) {
  int ls = r << 1;
  int rs = r << 1 | 1;
  (mul[ls] *= pow_mod(flag1[r], mid - L + 1)) %= mod;
  (flag1[ls] *= flag1[r]) %= mod;
  mask[ls] |= flag2[r];
  flag2[ls] |= flag2[r];
  (mul[rs] *= pow_mod(flag1[r], R - mid)) %= mod;
  (flag1[rs] *= flag1[r]) %= mod;
  mask[rs] |= flag2[r];
  flag2[rs] |= flag2[r];
  flag1[r] = 1;
  flag2[r] = 0;
}
pair<long long, long long> qry(int r, int L, int R, int x, int y) {
  if (L == x && R == y) return make_pair(mul[r], mask[r]);
  int mid = L + R >> 1;
  if (flag1[r] != 1 || flag2[r]) down(r, L, mid, R);
  if (y <= mid)
    return qry(r << 1, L, mid, x, y);
  else if (x > mid)
    return qry(r << 1 | 1, mid + 1, R, x, y);
  else {
    pair<long long, long long> ans1 = qry(r << 1, L, mid, x, mid);
    pair<long long, long long> ans2 = qry(r << 1 | 1, mid + 1, R, mid + 1, y);
    return make_pair(ans1.first * ans2.first % mod, ans1.second | ans2.second);
  }
}
void update(int r, int L, int R, int x, int y, int val, long long M) {
  if (L == x && R == y) {
    mul[r] *= pow_mod(val, R - L + 1);
    mul[r] %= mod;
    mask[r] |= M;
    flag1[r] *= val;
    flag1[r] %= mod;
    flag2[r] |= M;
    return;
  }
  int mid = L + R >> 1;
  if (flag1[r] != 1 || flag2[r]) down(r, L, mid, R);
  if (y <= mid)
    update(r << 1, L, mid, x, y, val, M);
  else if (x > mid)
    update(r << 1 | 1, mid + 1, R, x, y, val, M);
  else {
    update(r << 1, L, mid, x, mid, val, M);
    update(r << 1 | 1, mid + 1, R, mid + 1, y, val, M);
  }
  mul[r] = mul[r << 1] * mul[r << 1 | 1] % mod;
  mask[r] = mask[r << 1] | mask[r << 1 | 1];
}
int main() {
  for (int i = 2; i <= 300; ++i)
    if (prime(i)) {
      p[cnt] = i;
      inv[cnt++] = pow_mod(i, mod - 2);
    }
  scanf("%d%d", &n, &q);
  init(1, 1, n);
  while (q--) {
    scanf(" %s%d%d", cmd, &x, &y);
    if (cmd[0] == 'T') {
      pair<long long, long long> ans = qry(1, 1, n, x, y);
      for (int i = 0; i < cnt; ++i)
        if ((ans.second >> i) & 1) {
          ans.first *= inv[i];
          ans.first %= mod;
          ans.first *= p[i] - 1;
          ans.first %= mod;
        }
      printf("%I64d\n", ans.first);
    } else {
      scanf("%d", &z);
      update(1, 1, n, x, y, z, getmask(z));
    }
  }
  return 0;
}
