#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int MOD = 1e9 + 7;
pair<vector<int>, vector<int>> linear_sieve(const int UPBD) {
  vector<int> primes, last_prime(UPBD);
  for (int p = 2; p < UPBD; ++p) {
    if (not last_prime[p]) primes.push_back(p), last_prime[p] = p;
    for (int j = 0; primes[j] * p < UPBD; ++j) {
      last_prime[primes[j] * p] = primes[j];
      if (p % primes[j] == 0) break;
    }
  }
  return {primes, last_prime};
}
int LLmul(int a, int b) { return 1ll * a * b % MOD; }
template <typename F>
vector<F> linear_inv(F p, int k) {
  vector<F> inv(min(p, F(1 + k)));
  inv[1] = 1;
  for (int i = 2; i < inv.size(); ++i) inv[i] = LLmul((p - p / i), inv[p % i]);
  return inv;
}
auto inv = linear_inv(MOD, 303);
vector<long long> divPs;
vector<int> lp, pToID, primes;
int toFactor(long long a) {
  int ans = 1;
  for (int i = 0; i < 62; ++i) {
    if ((a >> i) & 1ll) ans = LLmul(LLmul(ans, primes[i] - 1), inv[primes[i]]);
  }
  return ans;
}
int powM(int a, int p) {
  int ret = 1;
  for (int cur = a; p; p >>= 1, cur = LLmul(cur, cur)) {
    if (p & 1) ret = LLmul(ret, cur);
  }
  return ret;
}
class Seg {
  long long bst = 0;
  long long bstTag = 0;
  int mul = 1;
  int mulTag = 1;
  int l, m, r;
  Seg* ch[2] = {};
  void pull() {
    mul = LLmul(ch[0]->mul, ch[1]->mul);
    bst = ch[0]->bst | ch[1]->bst;
  }
  void push() {
    if (bstTag) {
      for (int i = 0; i < 2; ++i) {
        ch[i]->bstTag |= bstTag;
        ch[i]->bst |= bstTag;
      }
      bstTag = 0;
    }
    if (mulTag != 1) {
      for (int i = 0; i < 2; ++i) {
        ch[i]->mulTag = LLmul(ch[i]->mulTag, mulTag);
        ch[i]->mul = LLmul(ch[i]->mul, powM(mulTag, ch[i]->size()));
      }
      mulTag = 1;
    }
  }

 public:
  int size() { return r - l; }
  Seg(int l, int r, const vector<int>& A) : l(l), r(r), m(l + r >> 1) {
    bst = 0;
    bstTag = 0;
    mul = 1;
    mulTag = 1;
    if (r - l == 1)
      mul = A[l], bst = divPs[A[l]];
    else {
      push();
      ch[0] = new Seg(l, m, A);
      ch[1] = new Seg(m, r, A);
      pull();
    }
  }
  void multiply(int ql, int qr, int v) {
    if (ql <= l and r <= qr)
      mul = LLmul(mul, powM(v, size())), mulTag = LLmul(mulTag, v);
    else {
      push();
      if (ql < m) ch[0]->multiply(ql, qr, v);
      if (m < qr) ch[1]->multiply(ql, qr, v);
      pull();
    }
  }
  void addSet(int ql, int qr, long long S) {
    if (ql <= l and r <= qr)
      bst |= S, bstTag |= S;
    else {
      push();
      if (ql < m) ch[0]->addSet(ql, qr, S);
      if (m < qr) ch[1]->addSet(ql, qr, S);
      pull();
    }
  }
  int multiplication(int ql, int qr) {
    if (ql <= l and r <= qr)
      return mul;
    else {
      int ret = 1;
      push();
      if (ql < m) ret = LLmul(ret, ch[0]->multiplication(ql, qr));
      if (m < qr) ret = LLmul(ret, ch[1]->multiplication(ql, qr));
      pull();
      return ret;
    }
  }
  long long factor(int ql, int qr) {
    if (ql <= l and r <= qr)
      return bst;
    else {
      long long ret = 0;
      push();
      if (ql < m) ret |= ch[0]->factor(ql, qr);
      if (m < qr) ret |= ch[1]->factor(ql, qr);
      pull();
      return ret;
    }
  }
};
class Solution {
  int n, q;

 public:
  void run() {
    cin >> n >> q;
    tie(primes, lp) = linear_sieve(301);
    pToID.resize(301);
    divPs.assign(301, 0);
    for (int i = 0; i < primes.size(); ++i) pToID[primes[i]] = i;
    for (int p = 2; p < 301; ++p)
      if (lp[p] == p) {
        for (int j = p; j < 301; j += p) divPs[j] |= 1ll << pToID[p];
      }
    vector<int> A(n);
    for (int i = 0; i < n; ++i) cin >> A[i];
    Seg root(0, n, A);
    while (q--) {
      string s;
      int l, r;
      cin >> s >> l >> r;
      --l;
      if (s == "TOTIENT") {
        cout << LLmul(root.multiplication(l, r), toFactor(root.factor(l, r)))
             << '\n';
      } else {
        int x;
        cin >> x;
        if (x == 1) continue;
        root.multiply(l, r, x);
        root.addSet(l, r, divPs[x]);
      }
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Solution().run();
}
