#include <bits/stdc++.h>
using namespace std;
long long Pow[65] = {0}, MOD = 1000000007, Q = 0;
long long all[400005];
long long what[305];
long long which[305], now = 1;
long long have[305] = {0};
long long All[65];
char temp[15];
long long Pow2(long long N, long long M) {
  if (M == 0) return 1;
  long long t = Pow2(N, M / 2);
  t *= t;
  t %= MOD;
  if (M % 2) t *= N;
  t %= MOD;
  return t;
}
struct A {
  long long l, r;
  long long nxl;
  long long nxr;
  long long allt;
  long long Pt;
  long long P;
  long long all;
} Node[2000005];
void build(long long l, long long r, long long here) {
  long long i;
  Node[here].l = l;
  Node[here].r = r;
  Node[here].P = 0;
  Node[here].Pt = 0;
  Node[here].allt = 1;
  Node[here].all = 1;
  if (l == r) {
    Node[here].all = all[l];
    for (i = 0; i < 62; i++)
      if (all[l] % what[i] == 0) Node[here].P |= Pow[i];
    return;
  }
  Node[here].nxl = now++;
  Node[here].nxr = now++;
  build(l, (l + r) / 2, Node[here].nxl);
  build((l + r) / 2 + 1, r, Node[here].nxr);
  Node[here].all = Node[Node[here].nxl].all * Node[Node[here].nxr].all % MOD;
  Node[here].P = Node[Node[here].nxl].P | Node[Node[here].nxr].P;
}
void change(long long l, long long r, long long here, long long &t,
            long long &X) {
  long long i;
  Node[here].P |= X;
  Node[here].all *= Pow2(t, r - l + 1);
  Node[here].all %= MOD;
  if (l == Node[here].l && r == Node[here].r) {
    Node[here].allt *= t;
    Node[here].allt %= MOD;
    Node[here].Pt |= X;
    Node[here].P |= X;
    return;
  } else if (r <= (Node[here].l + Node[here].r) / 2)
    change(l, r, Node[here].nxl, t, X);
  else if (l > (Node[here].l + Node[here].r) / 2)
    change(l, r, Node[here].nxr, t, X);
  else {
    change(l, (Node[here].l + Node[here].r) / 2, Node[here].nxl, t, X);
    change((Node[here].l + Node[here].r) / 2 + 1, r, Node[here].nxr, t, X);
  }
}
pair<long long, long long> con(long long l, long long r, long long here) {
  if (l == Node[here].l && r == Node[here].r)
    return make_pair(Node[here].all, Node[here].P);
  Node[Node[here].nxl].allt *= Node[here].allt;
  Node[Node[here].nxl].allt %= MOD;
  Node[Node[here].nxl].all *= Pow2(
      Node[here].allt, Node[Node[here].nxl].r - Node[Node[here].nxl].l + 1);
  Node[Node[here].nxl].all %= MOD;
  Node[Node[here].nxl].Pt |= Node[here].Pt;
  Node[Node[here].nxl].P |= Node[here].Pt;
  Node[Node[here].nxr].allt *= Node[here].allt;
  Node[Node[here].nxr].allt %= MOD;
  Node[Node[here].nxr].all *= Pow2(
      Node[here].allt, Node[Node[here].nxr].r - Node[Node[here].nxr].l + 1);
  Node[Node[here].nxr].all %= MOD;
  Node[Node[here].nxr].Pt |= Node[here].Pt;
  Node[Node[here].nxr].P |= Node[here].Pt;
  Node[here].allt = 1;
  Node[here].Pt = 0;
  if (r <= (Node[here].l + Node[here].r) / 2)
    return con(l, r, Node[here].nxl);
  else if (l > (Node[here].l + Node[here].r) / 2)
    return con(l, r, Node[here].nxr);
  else {
    pair<long long, long long> t1 =
        con(l, (Node[here].l + Node[here].r) / 2, Node[here].nxl);
    pair<long long, long long> t2 =
        con((Node[here].l + Node[here].r) / 2 + 1, r, Node[here].nxr);
    return make_pair(t1.first * t2.first % MOD, t1.second | t2.second);
  }
}
int main() {
  long long N, M, i, j, l, r, t, X = 0;
  long long ans;
  Pow[0] = 1;
  for (i = 1; i < 65; i++) Pow[i] = Pow[i - 1] * 2;
  for (i = 2; i <= 300; i++) {
    if (!have[i]) {
      what[Q] = i;
      which[i] = Q;
      All[Q] = Pow2(i, MOD - 2);
      All[Q] *= (i - 1);
      All[Q] %= MOD;
      Q++;
      for (j = i * i; j <= 300; j += i) have[j] = 1;
    }
  }
  scanf("%lld %lld", &N, &M);
  for (i = 0; i < N; i++) scanf("%lld", &all[i]);
  build(0, N - 1, 0);
  while (M--) {
    scanf("%s", temp);
    if (temp[0] == 'T') {
      ans = 1;
      scanf("%lld %lld", &l, &r);
      l--;
      r--;
      pair<long long, long long> T;
      T = con(l, r, 0);
      ans = T.first;
      for (i = 0; i < Q; i++) {
        if (T.second & Pow[i]) {
          ans *= All[i];
          ans %= MOD;
        }
      }
      printf("%lld\n", ans);
    } else {
      scanf("%lld %lld %lld", &l, &r, &t);
      X = 0;
      for (i = 0; i < 62; i++)
        if (t % what[i] == 0) X |= Pow[i];
      l--;
      r--;
      change(l, r, 0, t, X);
    }
  }
  return 0;
}
