#include <bits/stdc++.h>
using namespace std;
bool endline = false;
template <class T>
istream& operator>>(istream& inp, vector<T>& v) {
  for (auto& it : v) inp >> it;
  return inp;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto& it : v) out << it << (endline ? "\n" : " ");
  return out;
}
template <class T, class U>
istream& operator>>(istream& inp, pair<T, U>& v) {
  inp >> v.first >> v.second;
  return inp;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U>& v) {
  out << v.first << ' ' << v.second;
  return out;
}
void debug() { cout << endl; }
template <typename H, typename... T>
void debug(H a, T... b) {
  cout << a << ' ';
  debug(b...);
}
void FAST_IO(string filein = "", string fileout = "") {
  if (fopen(filein.c_str(), "r")) {
    freopen(filein.c_str(), "r", stdin);
    freopen(fileout.c_str(), "w", stdout);
  }
  cin.tie(0), cout.tie(0)->sync_with_stdio(0);
}
void Hollwo_Pelw();
signed main() {
  FAST_IO(".inp", ".out");
  int testcases = 1;
  for (int test = 1; test <= testcases; test++) {
    Hollwo_Pelw();
  }
  return 0;
}
const int allmod[3] = {(int)1e9 + 7, 998244353, (int)1e9 + 9};
const int mod = allmod[0];
const int MAXN = 4e5 + 5;
const int inf = 2e9;
const long long linf = 1e18;
long long mask[303], pr[303], C[303];
vector<long long> primes;
long long binpow(long long a, long long x) {
  long long r = 1;
  while (x) {
    if (x & 1) r = r * a % mod;
    x >>= 1;
    a = a * a % mod;
  }
  return r;
}
struct node {
  long long msk, product, lzmsk, lzproduct;
} st[MAXN << 2];
long long n, q, a[MAXN];
node merge(node l, node r) {
  return {l.msk | r.msk, l.product * r.product % mod, 0, 1};
}
void build(long long id, long long tl, long long tr) {
  if (tl == tr) {
    st[id] = {mask[a[tl]], a[tl], 0, 1};
  } else {
    long long tm = tl + tr >> 1;
    build(id << 1, tl, tm), build(id << 1 | 1, tm + 1, tr);
    st[id] = merge(st[id << 1], st[id << 1 | 1]);
  }
}
void apply(long long id, long long tl, long long tr, long long x,
           long long msk) {
  st[id].msk |= msk;
  st[id].lzmsk |= msk;
  (st[id].product *= binpow(x, tr - tl + 1)) %= mod;
  (st[id].lzproduct *= x) %= mod;
}
void push(long long id, long long tl, long long tr) {
  long long tm = tl + tr >> 1;
  apply(id << 1, tl, tm, st[id].lzproduct, st[id].lzmsk);
  apply(id << 1 | 1, tm + 1, tr, st[id].lzproduct, st[id].lzmsk);
  st[id].lzproduct = 1;
  st[id].lzmsk = 0;
}
void upd(long long l, long long r, long long x, long long id = 1,
         long long tl = 1, long long tr = n) {
  if (l > r || tl > r || l > tr) return;
  if (l <= tl && tr <= r) return apply(id, tl, tr, x, mask[x]);
  long long tm = tl + tr >> 1;
  push(id, tl, tr);
  upd(l, r, x, id << 1, tl, tm), upd(l, r, x, id << 1 | 1, tm + 1, tr);
  st[id] = merge(st[id << 1], st[id << 1 | 1]);
}
node query(long long l, long long r, long long id = 1, long long tl = 1,
           long long tr = n) {
  if (l > r || tl > r || l > tr) return {0, 1, 0, 1};
  if (l <= tl && tr <= r) return st[id];
  long long tm = tl + tr >> 1;
  push(id, tl, tr);
  return merge(query(l, r, id << 1, tl, tm),
               query(l, r, id << 1 | 1, tm + 1, tr));
}
long long calc(node x) {
  long long r = x.product;
  for (long long i = 0; i < primes.size(); i++) {
    if (x.msk >> i & 1) {
      r = r * C[primes[i]] % mod;
    }
  }
  return r;
}
void Hollwo_Pelw() {
  for (long long i = 2; i <= 300; i++) pr[i] = 1;
  for (long long i = 2; i <= 300; i++) {
    if (pr[i]) {
      primes.push_back(i);
      for (long long j = i * i; j <= 300; j += i) pr[j] = 0;
      C[i] = (i - 1) * binpow(i, mod - 2) % mod;
    }
    for (long long j = 0; j < primes.size(); j++)
      if (i % primes[j] == 0) mask[i] |= 1ll << j;
  }
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  build(1, 1, n);
  while (q--) {
    string t;
    long long l, r, x;
    cin >> t >> l >> r;
    if (t[0] == 'T')
      cout << calc(query(l, r)) << "\n";
    else
      cin >> x, upd(l, r, x);
  }
}
