#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  long long pos = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') pos = 0;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  return pos ? x : -x;
}
const long long N = 500001;
long long mod = 1000000007;
long long n, q, a[N];
long long val[N << 2], tag[N << 2], val1[N << 2], tag1[N << 2], pri[N], vis[N],
    inv[N], f[N], pl;
long long ksm(long long aa, long long bb) {
  long long cc = 1;
  while (bb) {
    if (bb & 1) {
      cc = cc * aa % mod;
    }
    aa = aa * aa % mod;
    bb >>= 1;
  }
  return cc;
}
void push_down(long long now) {
  if (tag[now]) {
    val[now << 1] |= tag[now];
    val[now << 1 | 1] |= tag[now];
    tag[now << 1] |= tag[now];
    tag[now << 1 | 1] |= tag[now];
    tag[now] = 0;
  }
}
void push_down1(long long now, long long l, long long r) {
  if (tag1[now] != 1ll) {
    long long mid = (l + r) >> 1;
    val1[now << 1] = val1[now << 1] * ksm(tag1[now], (mid - l + 1)) % mod;
    val1[now << 1 | 1] = val1[now << 1 | 1] * ksm(tag1[now], (r - mid)) % mod;
    tag1[now << 1] = tag1[now << 1] * tag1[now] % mod;
    tag1[now << 1 | 1] = tag1[now << 1 | 1] * tag1[now] % mod;
    tag1[now] = 1ll;
  }
}
void insert(long long now, long long l, long long r, long long pos,
            long long sta) {
  val[now] |= sta;
  if (l == r) return;
  long long mid = (l + r) >> 1;
  if (pos <= mid)
    insert(now << 1, l, mid, pos, sta);
  else
    insert(now << 1 | 1, mid + 1, r, pos, sta);
}
void insert1(long long now, long long l, long long r, long long pos,
             long long w) {
  if (tag1[now] == 0) tag1[now] = 1ll;
  if (val1[now] == 0) val1[now] = 1ll;
  val1[now] = val1[now] * w % mod;
  if (l == r) return;
  long long mid = (l + r) >> 1;
  if (pos <= mid)
    insert1(now << 1, l, mid, pos, w);
  else
    insert1(now << 1 | 1, mid + 1, r, pos, w);
}
long long query(long long now, long long l, long long r, long long ql,
                long long qr) {
  if (ql <= l && r <= qr) return val[now];
  long long mid = (l + r) >> 1;
  push_down(now);
  long long ans = 0;
  if (ql <= mid) ans |= query(now << 1, l, mid, ql, qr);
  if (mid < qr) ans |= query(now << 1 | 1, mid + 1, r, ql, qr);
  return ans;
}
long long query1(long long now, long long l, long long r, long long ql,
                 long long qr) {
  if (ql <= l && r <= qr) return val1[now];
  long long mid = (l + r) >> 1;
  push_down1(now, l, r);
  long long ans = 1ll;
  if (ql <= mid) ans = ans * query1(now << 1, l, mid, ql, qr) % mod;
  if (mid < qr) ans = ans * query1(now << 1 | 1, mid + 1, r, ql, qr) % mod;
  return ans;
}
void push_up(long long now) { val[now] = val[now << 1] | val[now << 1 | 1]; }
void push_up1(long long now) {
  val1[now] = val1[now << 1] * val1[now << 1 | 1] % mod;
}
void change(long long now, long long l, long long r, long long ql, long long qr,
            long long sta) {
  if (ql <= l && r <= qr) {
    val[now] |= sta;
    tag[now] |= sta;
    return;
  }
  push_down(now);
  long long mid = (l + r) >> 1;
  if (ql <= mid) change(now << 1, l, mid, ql, qr, sta);
  if (mid < qr) change(now << 1 | 1, mid + 1, r, ql, qr, sta);
  push_up(now);
}
void change1(long long now, long long l, long long r, long long ql,
             long long qr, long long w) {
  if (ql <= l && r <= qr) {
    val1[now] = val1[now] * ksm(w, (r - l + 1)) % mod;
    tag1[now] = tag1[now] * w % mod;
    return;
  }
  push_down1(now, l, r);
  long long mid = (l + r) >> 1;
  if (ql <= mid) change1(now << 1, l, mid, ql, qr, w);
  if (mid < qr) change1(now << 1 | 1, mid + 1, r, ql, qr, w);
  push_up1(now);
}
char s[10];
int main() {
  n = read(), q = read();
  for (register long long i = (2); i <= (300); ++i) {
    if (!vis[i]) pri[++pl] = i;
    for (long long j = 1; j <= pl && i * pri[j] <= 300; j++) {
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
  inv[1] = 1;
  for (register long long i = (2); i <= (300); ++i)
    inv[i] = mod - 1ll * (mod / i) * inv[mod % i] % mod;
  for (register long long i = (1); i <= (pl); ++i)
    f[i] = 1ll * inv[pri[i]] * (pri[i] - 1) % mod;
  for (register long long i = (1); i <= (n); ++i) {
    a[i] = read();
    long long sta = 0;
    for (long long j = 1; j <= pl; j++) {
      if (a[i] % pri[j] == 0) sta |= (1ll << (j - 1));
    }
    insert(1, 1, n, i, sta);
    insert1(1, 1, n, i, a[i]);
  }
  long long l, r, x;
  for (register long long i = (1); i <= (q); ++i) {
    scanf("%s", s);
    l = read(), r = read();
    if (s[0] == 'T') {
      long long nsta = query(1, 1, n, l, r);
      long long phi = query1(1, 1, n, l, r);
      for (long long j = 1; j <= pl; j++) {
        if (nsta & (1ll << (j - 1))) {
          phi = phi * f[j] % mod;
        }
      }
      printf("%lld\n", phi);
    } else {
      x = read();
      long long sta = 0;
      for (long long j = 1; j <= pl; j++) {
        if (x % pri[j] == 0) sta |= (1ll << (j - 1));
      }
      change(1, 1, n, l, r, sta);
      change1(1, 1, n, l, r, x);
    }
  }
  return 0;
}
