#include <bits/stdc++.h>
using namespace std;
const int N = 400005, P = 1000000007;
using ll = long long;
int n, q, pr[305], a[N], idx;
bool npr[305];
ll f[305];
struct TNode {
  int l, r;
  ll v, fl;
} t[N << 2];
ll lazy1[N << 2], lazy2[N << 2];
ll qpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % P;
    a = a * a % P;
    b >>= 1;
  }
  return ret;
}
inline int lc(int pos) { return pos << 1; }
inline int rc(int pos) { return pos << 1 | 1; }
inline void pushup(TNode &pos, TNode l, TNode r) {
  pos.fl = l.fl | r.fl;
  pos.v = l.v * r.v % P;
}
void push(int pos, ll v, ll fl) {
  lazy1[pos] = lazy1[pos] * v % P;
  lazy2[pos] |= fl;
  t[pos].v = qpow(v, t[pos].r - t[pos].l + 1) * t[pos].v % P;
  t[pos].fl |= fl;
}
void pushdown(int pos) {
  if (!lazy2[pos]) return;
  push(lc(pos), lazy1[pos], lazy2[pos]);
  push(rc(pos), lazy1[pos], lazy2[pos]);
  lazy1[pos] = 1;
  lazy2[pos] = 0;
}
void build(int pos, int l, int r) {
  lazy1[pos] = 1;
  t[pos].l = l;
  t[pos].r = r;
  if (l == r) {
    t[pos].v = a[l];
    for (int i = 1; i <= idx; i++)
      if (a[l] % pr[i] == 0) t[pos].fl |= 1ll << (i - 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(lc(pos), l, mid);
  build(rc(pos), mid + 1, r);
  pushup(t[pos], t[lc(pos)], t[rc(pos)]);
}
void modify(int pos, int l, int r, ll v, ll fl) {
  if (t[pos].l == l && t[pos].r == r) return push(pos, v, fl);
  pushdown(pos);
  int mid = (t[pos].l + t[pos].r) >> 1;
  if (r <= mid)
    modify(lc(pos), l, r, v, fl);
  else if (l > mid)
    modify(rc(pos), l, r, v, fl);
  else
    modify(lc(pos), l, mid, v, fl), modify(rc(pos), mid + 1, r, v, fl);
  pushup(t[pos], t[lc(pos)], t[rc(pos)]);
}
TNode query(int pos, int l, int r) {
  if (t[pos].l == l && t[pos].r == r) return t[pos];
  pushdown(pos);
  int mid = (t[pos].l + t[pos].r) >> 1;
  if (r <= mid) return query(lc(pos), l, r);
  if (l > mid) return query(rc(pos), l, r);
  TNode ans;
  pushup(ans, query(lc(pos), l, mid), query(rc(pos), mid + 1, r));
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 2; i <= 300; i++) {
    if (!npr[i]) pr[++idx] = i;
    for (int j = 1; j <= idx && i * pr[j] <= 300; j++) {
      npr[i * pr[j]] = 1;
      if (i % pr[j] == 0) break;
    }
  }
  for (int i = 1; i <= idx; i++) f[i] = (pr[i] - 1) * qpow(pr[i], P - 2) % P;
  build(1, 1, n);
  for (int i = 1; i <= q; i++) {
    int l, r;
    char op[20];
    cin >> op >> l >> r;
    if (op[0] == 'M') {
      ll x, y = 0;
      cin >> x;
      for (int i = 1; i <= idx; i++)
        if (x % pr[i] == 0) y |= 1ll << (i - 1);
      modify(1, l, r, x, y);
    } else {
      TNode ans = query(1, l, r);
      ll phi = ans.v;
      for (int i = 1; i <= idx; i++)
        if (ans.fl & (1ll << (i - 1))) phi = phi * f[i] % P;
      cout << phi << endl;
    }
  }
  return 0;
}
