#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
const int MAX_N = 4e5 + 5, M = 301, Lim = 62;
int P[Lim] = {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};
int rev[M] = {
    0, 0,  0, 1,  0, 2,  0, 3,  0, 0,  0, 4, 0, 5,  0, 0,  0, 6,  0, 7,  0, 0,
    0, 8,  0, 0,  0, 0,  0, 9,  0, 10, 0, 0, 0, 0,  0, 11, 0, 0,  0, 12, 0, 13,
    0, 0,  0, 14, 0, 0,  0, 0,  0, 15, 0, 0, 0, 0,  0, 16, 0, 17, 0, 0,  0, 0,
    0, 18, 0, 0,  0, 19, 0, 20, 0, 0,  0, 0, 0, 21, 0, 0,  0, 22, 0, 0,  0, 0,
    0, 23, 0, 0,  0, 0,  0, 0,  0, 24, 0, 0, 0, 25, 0, 26, 0, 0,  0, 27, 0, 28,
    0, 0,  0, 29, 0, 0,  0, 0,  0, 0,  0, 0, 0, 0,  0, 0,  0, 30, 0, 0,  0, 31,
    0, 0,  0, 0,  0, 32, 0, 33, 0, 0,  0, 0, 0, 0,  0, 0,  0, 34, 0, 35, 0, 0,
    0, 0,  0, 36, 0, 0,  0, 0,  0, 37, 0, 0, 0, 38, 0, 0,  0, 0,  0, 39, 0, 0,
    0, 0,  0, 40, 0, 41, 0, 0,  0, 0,  0, 0, 0, 0,  0, 42, 0, 43, 0, 0,  0, 44,
    0, 45, 0, 0,  0, 0,  0, 0,  0, 0,  0, 0, 0, 46, 0, 0,  0, 0,  0, 0,  0, 0,
    0, 0,  0, 47, 0, 0,  0, 48, 0, 49, 0, 0, 0, 50, 0, 0,  0, 0,  0, 51, 0, 52,
    0, 0,  0, 0,  0, 0,  0, 0,  0, 53, 0, 0, 0, 0,  0, 54, 0, 0,  0, 0,  0, 55,
    0, 0,  0, 0,  0, 56, 0, 57, 0, 0,  0, 0, 0, 58, 0, 0,  0, 59, 0, 60, 0, 0,
    0, 0,  0, 0,  0, 0,  0, 61, 0, 0,  0, 0, 0, 0,  0};
long long val[MAX_N << 2], col[MAX_N << 2];
long long now, Ans, s[MAX_N << 2], colf[MAX_N << 2];
void up(int rt, int l, int r) {
  s[rt] = s[rt << 1] | s[rt << 1 | 1];
  val[rt] = 1ll * val[rt << 1] * val[rt << 1 | 1] % 1000000007;
}
long long FP(int x, int k) {
  long long t = 1;
  for (; k; k >>= 1, x = 1ll * x * x % 1000000007)
    if (k & 1) t = 1ll * t * x % 1000000007;
  return t;
}
void update(int rt, int l, int r, long long v, long long vf) {
  val[rt] = 1ll * val[rt] * FP(v, r - l + 1) % 1000000007;
  col[rt] = 1ll * col[rt] * v % 1000000007;
  s[rt] |= vf;
  colf[rt] |= vf;
}
void build(int rt, int l, int r) {
  col[rt] = 1;
  if (l == r) {
    int v;
    scanf("%d", &v);
    val[rt] = v;
    for (int i = 0; i < Lim && P[i] * P[i] <= v; ++i) {
      if (v % P[i] == 0) {
        s[rt] |= 1ll << i, v /= P[i];
        while (v % P[i] == 0) v /= P[i];
      }
    }
    if (v != 1) s[rt] |= 1ll << rev[v];
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid), build(rt << 1 | 1, mid + 1, r);
  up(rt, l, r);
}
void down(int rt, int l, int r) {
  int mid = (l + r) >> 1;
  update(rt << 1, l, mid, col[rt], colf[rt]);
  update(rt << 1 | 1, mid + 1, r, col[rt], colf[rt]);
  col[rt] = 1;
  colf[rt] = 0;
}
void modify(int rt, int l, int r, int x, int y, long long v) {
  if (x <= l && r <= y) {
    update(rt, l, r, v, now);
    return;
  }
  if (col[rt] != 1) down(rt, l, r);
  int mid = (l + r) >> 1;
  if (x <= mid) modify(rt << 1, l, mid, x, y, v);
  if (mid < y) modify(rt << 1 | 1, mid + 1, r, x, y, v);
  up(rt, l, r);
}
long long query(int rt, int l, int r, int x, int y) {
  if (x <= l && r <= y) return Ans |= s[rt], val[rt];
  if (col[rt] != 1) down(rt, l, r);
  int mid = (l + r) >> 1;
  if (x <= mid)
    if (mid < y)
      return 1ll * query(rt << 1, l, mid, x, y) *
             query(rt << 1 | 1, mid + 1, r, x, y) % 1000000007;
    else
      return query(rt << 1, l, mid, x, y);
  return query(rt << 1 | 1, mid + 1, r, x, y);
}
int inv[M], coef[M];
char str[15];
int main() {
  inv[1] = 1;
  for (int i = 2; i < M; ++i)
    inv[i] =
        1ll * (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;
  for (int i = 0; i < Lim; i++)
    coef[i] = 1ll * (P[i] - 1) * inv[P[i]] % 1000000007;
  int n, q, x, y;
  scanf("%d%d", &n, &q);
  build(1, 1, n);
  while (q--) {
    scanf("%s", str);
    if (str[0] == 'T') {
      Ans = 0;
      scanf("%d%d", &x, &y);
      long long VAL = query(1, 1, n, x, y);
      for (int i = 0; i < Lim; ++i)
        if (Ans >> i & 1) VAL = 1ll * VAL * coef[i] % 1000000007;
      printf("%lld\n", VAL);
    } else {
      int V, tmp;
      scanf("%d%d%d", &x, &y, &tmp);
      V = tmp;
      now = 0;
      for (int i = 0; i < Lim && P[i] * P[i] <= V; ++i) {
        if (V % P[i] == 0) {
          now |= 1 << i, V /= P[i];
          while (V % P[i] == 0) V /= P[i];
        }
      }
      if (V != 1) now |= 1ll << rev[V];
      modify(1, 1, n, x, y, tmp);
    }
  }
  return 0;
}
