#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 400031;
long long pw(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2) return a * pw(a, b - 1) % 1000000007;
  return pw(a * a % 1000000007, b / 2);
}
long long inver[331];
int pr[331];
vector<int> primes;
int n;
int tests;
int ar[N];
long long M[N];
pair<long long, long long> t[N * 4];
pair<long long, long long> tomult[N * 4];
long long get_pw(long long val, int p) { return pw(val, p); }
void push(int v, int tl, int tr) {
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  if (tomult[v].first != 1) {
    tomult[v * 2].first = (tomult[v * 2].first * tomult[v].first) % 1000000007;
    tomult[v * 2 + 1].first =
        (tomult[v * 2 + 1].first * tomult[v].first) % 1000000007;
    long long le = get_pw(tomult[v].first, sdfjahlfasfh - tl + 1);
    long long ri = get_pw(tomult[v].first, tr - sdfjahlfasfh);
    t[v * 2].first = (t[v * 2].first * le) % 1000000007;
    t[v * 2 + 1].first = (t[v * 2 + 1].first * ri) % 1000000007;
    tomult[v].first = 1;
  }
  if (tomult[v].second != 0) {
    tomult[v * 2].second |= tomult[v].second;
    tomult[v * 2 + 1].second |= tomult[v].second;
    t[v * 2].second |= tomult[v].second;
    t[v * 2 + 1].second |= tomult[v].second;
    tomult[v].second = 0;
  }
}
void build(int v, int tl, int tr) {
  tomult[v].first = 1;
  if (tl == tr) {
    t[v].first = ar[tl];
    t[v].second = M[tl];
    return;
  }
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  build(v * 2, tl, sdfjahlfasfh);
  build(v * 2 + 1, sdfjahlfasfh + 1, tr);
  t[v].first = (t[v * 2].first * t[v * 2 + 1].first) % 1000000007;
  t[v].second = (t[v * 2].second | t[v * 2 + 1].second);
}
void update(int v, int tl, int tr, int l, int r, int val, long long msk) {
  if (l > r) return;
  if (tl == l && tr == r) {
    t[v].first = t[v].first * get_pw(val, tr - tl + 1) % 1000000007;
    t[v].second |= msk;
    tomult[v].first *= val;
    tomult[v].first %= 1000000007;
    tomult[v].second |= msk;
    return;
  }
  push(v, tl, tr);
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  update(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh), val, msk);
  update(v * 2 + 1, sdfjahlfasfh + 1, tr, max(sdfjahlfasfh + 1, l), r, val,
         msk);
  t[v].first = t[v * 2].first * t[v * 2 + 1].first % 1000000007;
  t[v].second = (t[v * 2].second | t[v * 2 + 1].second);
}
pair<long long, long long> get(int v, int tl, int tr, int l, int r) {
  if (l > r) return make_pair(1, 0);
  if (l == tl && r == tr) return t[v];
  push(v, tl, tr);
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  pair<long long, long long> p1 =
      get(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh));
  pair<long long, long long> p2 =
      get(v * 2 + 1, sdfjahlfasfh + 1, tr, max(sdfjahlfasfh + 1, l), r);
  p1.first = (p1.first * p2.first) % 1000000007;
  p1.second |= p2.second;
  return p1;
}
int main() {
  pr[1] = 1;
  for (int i = 2; i <= 300; i++) {
    if (pr[i] == 0) {
      for (int j = i * 2; j <= 300; j += i) {
        pr[j] = 1;
      }
    }
  }
  for (int i = 1; i <= 300; i++) {
    inver[i] = pw(i, 1000000007 - 2);
  }
  for (int i = 2; i <= 300; i++) {
    if (pr[i] == 0) primes.push_back(i);
  }
  cin >> n >> tests;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
  }
  for (int i = 1; i <= n; i++) {
    long long msk = 0;
    for (int j = 0; j < primes.size(); j++) {
      if (ar[i] % primes[j] == 0) {
        msk |= (1ll << j);
      }
    }
    M[i] = msk;
  }
  build(1, 1, n);
  for (; tests; --tests) {
    string s;
    cin >> s;
    if (s == "TOTIENT") {
      int l, r;
      scanf("%d", &l);
      scanf("%d", &r);
      pair<long long, long long> res = get(1, 1, n, l, r);
      for (int i = 0; i < primes.size(); i++) {
        if (res.second & (1ll << i)) {
          res.first = res.first * inver[primes[i]];
          res.first %= 1000000007;
          res.first *= primes[i] - 1;
          res.first %= 1000000007;
        }
      }
      printf("%lld\n", res.first);
    } else {
      int l, r, val;
      scanf("%d", &l);
      scanf("%d", &r);
      scanf("%d", &val);
      long long msk = 0;
      for (int j = 0; j < primes.size(); j++) {
        if (val % primes[j] == 0) {
          msk |= (1ll << j);
        }
      }
      update(1, 1, n, l, r, val, msk);
    }
  }
  return 0;
}
