#include <bits/stdc++.h>
using namespace std;
int T[1050000], Lazy[1050000];
long long Mask[1050000], LazyMask[1050000];
bool p[301];
int pos, out;
int N, Q, Start, End, primes[63], inverse[63], TotalPrimes = -1, Pos, Val,
                                               ans[400005], v[400005], idx;
long long mask, M[301];
char s, f[1 << 17], Out[1 << 17], str[10];
inline void Write_Ch(char ch) {
  Out[out++] = ch;
  if (out == 1 << 17) fwrite(Out, 1 << 17, 1, stdout), out = 0;
}
inline void Write_Int(int nr) {
  int x = 0;
  do {
    str[x++] = nr % 10 + '0';
    nr /= 10;
  } while (nr);
  while (x > 0) Write_Ch(str[--x]);
}
inline void Read(int &nr) {
  nr = 0;
  while (f[pos] < '0' || f[pos] > '9') {
    pos++;
    if (pos == 1 << 17) fread(f, 1 << 17, 1, stdin), pos = 0;
  }
  while (f[pos] >= '0' && f[pos] <= '9') {
    nr = 10 * nr + f[pos++] - '0';
    if (pos == 1 << 17) fread(f, 1 << 17, 1, stdin), pos = 0;
  }
}
inline void ReadStr(char &s) {
  s = 0;
  while (f[pos] < 'A' || f[pos] > 'Z') {
    pos++;
    if (pos == 1 << 17) fread(f, 1 << 17, 1, stdin), pos = 0;
  }
  while (f[pos] >= 'A' && f[pos] <= 'Z') {
    if (s == 0) s = f[pos];
    pos++;
    if (pos == 1 << 17) fread(f, 1 << 17, 1, stdin), pos = 0;
  }
}
inline int LogPow(int base, int exp) {
  if (base == 1) return 1;
  int act = 1;
  for (int i = 0; i < 30; i++) {
    if (exp & (1 << i)) act = 1LL * act * base % 1000000007;
    base = 1LL * base * base % 1000000007;
  }
  return act;
}
inline void precalc() {
  for (int i = 1; i < 1050000; i++) T[i] = Lazy[i] = 1;
  for (int i = 2; i <= 300; i++) {
    if (!p[i]) {
      primes[++TotalPrimes] = i;
      inverse[TotalPrimes] = LogPow(i, 1000000007 - 2);
      for (int j = i; j <= 300; j += i) p[j] = 1, M[j] += (1LL << TotalPrimes);
    }
  }
}
inline void Propagate(int node, int s, int e) {
  T[node] = 1LL * T[node] * LogPow(Lazy[node], e - s + 1) % 1000000007;
  if (s != e) {
    Lazy[node << 1] = 1LL * Lazy[node << 1] * Lazy[node] % 1000000007;
    Lazy[(node << 1) + 1] =
        1LL * Lazy[(node << 1) + 1] * Lazy[node] % 1000000007;
  }
  Lazy[node] = 1;
  Mask[node] |= LazyMask[node];
  if (s != e) {
    LazyMask[node << 1] |= LazyMask[node];
    LazyMask[(node << 1) + 1] |= LazyMask[node];
  }
  LazyMask[node] = 0;
}
void DFS(int node, int s, int e) {
  if (s == e) {
    T[node] = v[s];
    Mask[node] = M[v[s]];
  } else {
    int mid = (s + e) >> 1;
    DFS(node << 1, s, mid);
    DFS((node << 1) + 1, mid + 1, e);
    T[node] = 1LL * T[node << 1] * T[(node << 1) + 1] % 1000000007;
    Mask[node] |= Mask[node << 1] | Mask[(node << 1) + 1];
  }
}
void Update(int node, int s, int e) {
  Propagate(node, s, e);
  if (Start <= s && e <= End) {
    Lazy[node] = 1LL * Lazy[node] * Val % 1000000007;
    LazyMask[node] |= M[Val];
  } else {
    int mid = (s + e) >> 1;
    if (Start <= mid) Update(node << 1, s, mid);
    if (End > mid) Update((node << 1) + 1, mid + 1, e);
    T[node] = 1LL * T[node << 1] * T[(node << 1) + 1] % 1000000007;
    T[node] = 1LL * T[node] * LogPow(Lazy[node << 1], mid - s + 1) % 1000000007;
    T[node] =
        1LL * T[node] * LogPow(Lazy[(node << 1) + 1], e - mid) % 1000000007;
    Mask[node] |= LazyMask[node << 1] | LazyMask[(node << 1) + 1] |
                  Mask[node << 1] | Mask[(node << 1) + 1];
  }
}
void Query(int node, int s, int e) {
  Propagate(node, s, e);
  if (Start <= s && e <= End) {
    Val = 1LL * Val * T[node] % 1000000007;
    mask |= Mask[node];
  } else {
    int mid = (s + e) >> 1;
    if (Start <= mid) Query(node << 1, s, mid);
    if (End > mid) Query((node << 1) + 1, mid + 1, e);
  }
}
int main() {
  fread(f, 1, 1 << 17, stdin);
  precalc();
  Read(N), Read(Q);
  for (int i = 1; i <= N; i++) Read(v[i]);
  DFS(1, 1, N);
  for (int i = 1; i <= Q; i++) {
    ReadStr(s);
    if (s == 'T') {
      Read(Start), Read(End);
      Val = 1;
      mask = 0;
      Query(1, 1, N);
      for (int j = 0; j <= TotalPrimes; j++)
        if (mask & (1LL << j))
          Val = 1LL * Val * inverse[j] % 1000000007 * (primes[j] - 1) %
                1000000007;
      Write_Int(Val), Write_Ch('\n');
    } else {
      Read(Start), Read(End), Read(Val);
      Update(1, 1, N);
    }
  }
  if (out > 0) fwrite(Out, 1, out, stdout);
  return 0;
}
