#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 4e5 + 10;
int a[maxn], n, q;
long long pri[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,
                   37,  41,  43,  47,  53,  59,  61,  67,  71,  73,  79,
                   83,  89,  97,  101, 103, 107, 109, 113, 127, 131, 137,
                   139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
                   197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257,
                   263, 269, 271, 277, 281, 283, 293};
long long ni[65];
long long pow_mod(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
struct tree {
  int left, right;
  long long sum, add;
  long long pos, lz;
} c[maxn << 2];
void build(int id, int l, int r) {
  c[id].left = l;
  c[id].right = r;
  c[id].add = 1;
  c[id].lz = 0;
  if (l == r) {
    c[id].sum = a[l];
    for (long long i = 0; i < 62; ++i) {
      if (a[l] % pri[i] == 0) {
        c[id].pos = (c[id].pos | (1ll << i));
        a[l] /= pri[i];
        while (a[l] % pri[i] == 0) a[l] /= pri[i];
      }
      if (a[l] < pri[i]) break;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  c[id].pos = ((c[id << 1].pos) | (c[id << 1 | 1].pos));
  c[id].sum = (c[id << 1].sum * c[id << 1 | 1].sum) % mod;
}
void pushdown(int id) {
  c[id << 1].sum =
      (c[id << 1].sum *
       pow_mod(c[id].add, (c[id << 1].right - c[id << 1].left + 1), mod)) %
      mod;
  c[id << 1 | 1].sum =
      (c[id << 1 | 1].sum *
       pow_mod(c[id].add, (c[id << 1 | 1].right - c[id << 1 | 1].left + 1),
               mod)) %
      mod;
  c[id << 1].add = c[id << 1].add * c[id].add % mod;
  c[id << 1 | 1].add = c[id << 1 | 1].add * c[id].add % mod;
  c[id].add = 1;
  c[id << 1].pos = (c[id << 1].pos | c[id].lz);
  c[id << 1 | 1].pos = (c[id << 1 | 1].pos | c[id].lz);
  c[id << 1].lz = (c[id << 1].lz | c[id].lz);
  c[id << 1 | 1].lz = (c[id << 1 | 1].lz | c[id].lz);
  c[id].lz = 0;
}
void update(int id, int l, int r, long long v, long long p) {
  if (c[id].left > r || c[id].right < l) return;
  if (c[id].left >= l && c[id].right <= r) {
    c[id].sum =
        (pow_mod(v, (c[id].right - c[id].left + 1), mod) * c[id].sum) % mod;
    c[id].add = (c[id].add * v) % mod;
    c[id].pos = (c[id].pos | p);
    c[id].lz = (p | c[id].lz);
    return;
  }
  if (c[id].add > 1) pushdown(id);
  if (c[id].lz) pushdown(id);
  update(id << 1, l, r, v, p);
  update(id << 1 | 1, l, r, v, p);
  c[id].sum = c[id << 1].sum * c[id << 1 | 1].sum % mod;
  c[id].pos = (c[id << 1].pos | c[id << 1 | 1].pos);
}
long long query_sum(int id, int l, int r) {
  if (r < c[id].left || l > c[id].right) return 1;
  if (c[id].left >= l && c[id].right <= r) {
    return c[id].sum;
  }
  if (c[id].add > 1) pushdown(id);
  long long ans = query_sum(id << 1, l, r) * query_sum(id << 1 | 1, l, r) % mod;
  c[id].sum = c[id << 1].sum * c[id << 1 | 1].sum % mod;
  return ans;
}
long long query_pos(int id, int l, int r) {
  if (r < c[id].left || l > c[id].right) return 0;
  if (c[id].left >= l && c[id].right <= r) {
    return c[id].pos;
  }
  if (c[id].lz) pushdown(id);
  long long pos = (query_pos(id << 1, l, r) | query_pos(id << 1 | 1, l, r));
  c[id].pos = (c[id << 1].pos | c[id << 1 | 1].pos);
  return pos;
}
char s[10];
int main() {
  for (int i = 0; i < 62; ++i) {
    ni[i] = pow_mod(pri[i], mod - 2, mod);
  }
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  build(1, 1, n);
  int l, r, x;
  long long ans, p;
  while (q--) {
    scanf("%s", s);
    if (s[0] == 'T') {
      scanf("%d%d", &l, &r);
      ans = query_sum(1, l, r);
      p = query_pos(1, l, r);
      for (long long i = 0; i < 62; ++i) {
        if ((p & (1ll << i)) != 0) {
          ans = ans * ni[i] % mod;
          ans = ans * (pri[i] - 1) % mod;
        }
      }
      printf("%lld\n", ans);
    } else {
      scanf("%d%d%d", &l, &r, &x);
      long long p = 0;
      long long v = x;
      for (long long i = 0; i < 62; ++i) {
        if (v % pri[i] == 0) {
          p = (p | (1ll << i));
          v /= pri[i];
          while (v % pri[i] == 0) v /= pri[i];
        }
        if (pri[i] > v) break;
      }
      update(1, l, r, x, p);
    }
  }
  return 0;
}
