#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<ll, ll>;
inline void NYA() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll fpow(ll b, ll p, ll mod) {
  ll ans = 1, now = b;
  while (p) {
    if (p & 1) ans = ans * now % mod;
    p /= 2;
    now = now * now % mod;
  }
  return ans;
}
ll fpow(ll b, ll p) { return fpow(b, p, (ll)(1e9 + 7)); }
void minify(ll &a, const ll &b) {
  if (b < a) a = b;
}
void maxify(ll &a, const ll &b) {
  if (b > a) a = b;
}
bool isprime(ll n) {
  for (ll i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
struct SegTree {
  ull tag[1600060];
  ull ans[1600060];
  void build() {
    memset(tag, 0, sizeof(tag));
    memset(ans, 0, sizeof(ans));
  }
  void add(ll id, ll l, ll r, ll L, ll R, ull mask) {
    if (l > R || r < L) return;
    if (l >= L && r <= R) {
      tag[id] |= mask;
      ans[id] |= mask;
      return;
    }
    ll m = (l + r) / 2;
    add((id * 2 + 1), l, m, L, R, mask);
    add((id * 2 + 2), m + 1, r, L, R, mask);
    ans[id] = ans[(id * 2 + 1)] | ans[(id * 2 + 2)] | tag[id];
  }
  ull ask(ll id, ll l, ll r, ll L, ll R) {
    if (l > R || r < L) return (ull)0;
    if (l >= L && r <= R) return ans[id];
    ll m = (l + r) / 2;
    return ask((id * 2 + 1), l, m, L, R) | ask((id * 2 + 2), m + 1, r, L, R) |
           tag[id];
  }
} seg;
struct SegTree2 {
  struct Node {
    ll ans, siz, tag;
  } a[1600060];
  inline ll Ans(ll id) {
    return a[id].ans * fpow(a[id].tag, a[id].siz) % (ll)(1e9 + 7);
  }
  inline void push(ll id) {
    a[(id * 2 + 1)].tag = a[(id * 2 + 1)].tag * a[id].tag % (ll)(1e9 + 7);
    a[(id * 2 + 2)].tag = a[(id * 2 + 2)].tag * a[id].tag % (ll)(1e9 + 7);
    a[id].tag = 1;
  }
  inline void pull(ll id) {
    a[id].ans = Ans((id * 2 + 1)) * Ans((id * 2 + 2)) % (ll)(1e9 + 7);
  }
  void build(ll id, ll l, ll r) {
    a[id].ans = 1;
    a[id].siz = r - l + 1;
    a[id].tag = 1;
    if (l == r) return;
    ll m = (l + r) / 2;
    build((id * 2 + 1), l, m);
    build((id * 2 + 2), m + 1, r);
  }
  void mul(ll id, ll l, ll r, ll L, ll R, ll x) {
    if (l > R || r < L) return;
    if (l >= L && r <= R) {
      a[id].tag = a[id].tag * x % (ll)(1e9 + 7);
      return;
    }
    ll m = (l + r) / 2;
    push(id);
    mul((id * 2 + 1), l, m, L, R, x);
    mul((id * 2 + 2), m + 1, r, L, R, x);
    pull(id);
  }
  ll ask(ll id, ll l, ll r, ll L, ll R) {
    if (l > R || r < L) return 1;
    if (l >= L && r <= R) return Ans(id);
    ll m = (l + r) / 2;
    push(id);
    ll ans = ask((id * 2 + 1), l, m, L, R) * ask((id * 2 + 2), m + 1, r, L, R) %
             (ll)(1e9 + 7);
    pull(id);
    return ans;
  }
} pro;
int32_t main() {
  NYA();
  vector<ll> pr;
  vector<ll> inv;
  for (ll i = 2; i <= 300; i++)
    if (isprime(i)) {
      pr.emplace_back(i);
      inv.emplace_back(fpow(i, (ll)(1e9 + 7) - 2));
    }
  ll n, q;
  cin >> n >> q;
  seg.build();
  pro.build(0, 1, n);
  for (ll id = 1; id <= n; id++) {
    ll t;
    cin >> t;
    pro.mul(0, 1, n, id, id, t);
    for (ll i = 0; i <= 61; i++) {
      ll cnt = 0;
      while (t % pr[i] == 0) {
        cnt++;
        t /= pr[i];
      }
      if (cnt) seg.add(0, 1, n, id, id, (1ll << i));
    }
  }
  string op;
  while (q--) {
    cin >> op;
    if (op[0] == 'M') {
      ll l, r, t;
      cin >> l >> r >> t;
      pro.mul(0, 1, n, l, r, t);
      for (ll i = 0; i <= 61; i++) {
        ll cnt = 0;
        while (t % pr[i] == 0) {
          cnt++;
          t /= pr[i];
        }
        if (cnt) seg.add(0, 1, n, l, r, (1ll << i));
      }
    } else {
      ll l, r;
      cin >> l >> r;
      ull mask = seg.ask(0, 1, n, l, r);
      ll ans = pro.ask(0, 1, n, l, r);
      for (ll i = 0; i <= 61; i++)
        if (mask & (1ll << i)) {
          ans = ans * inv[i] % (ll)(1e9 + 7) * (pr[i] - 1) % (ll)(1e9 + 7);
        }
      cout << ans << "\n";
    }
  }
  return 0;
}
