#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long a, long long b, long long m) {
  if (b == 0LL) return 1LL;
  if (b == 1LL) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1LL) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
bool is_prime(int p) {
  for (int i = 2; i * i <= p; i++) {
    if (p % i == 0) return 0;
  }
  return 1;
}
const int M = 1e9 + 7;
struct node {
  long long x, mask;
  node() {}
  node(long long x, long long mask) : x(x), mask(mask) {}
  node operator+(const node& o) const {
    node r;
    r.x = (x * o.x) % M;
    r.mask = mask | o.mask;
    return r;
  }
};
const int P = 310;
long long Mask[P];
long long modpow(long long b, long long e, long long mod) {
  long long ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1) ans = ans * b % mod;
  return ans;
}
int id[P];
const int N = 4e5 + 10;
node tree[4 * N];
node lazy[4 * N];
int a[N];
void build(int no, int i, int j) {
  lazy[no] = node(1, 0);
  if (i == j) {
    tree[no].x = a[i];
    tree[no].mask = Mask[a[i]];
    return;
  }
  int mid = (i + j) >> 1, l = no << 1, r = no << 1 | 1;
  build(l, i, mid);
  build(r, mid + 1, j);
  tree[no] = tree[l] + tree[r];
}
void flush(int no, int i, int j) {
  if (lazy[no].x != 1 or lazy[no].mask != 0) {
    tree[no].mask |= lazy[no].mask;
    tree[no].x = (tree[no].x * modpow(lazy[no].x, j - i + 1, M)) % M;
    int l = no << 1, r = no << 1 | 1;
    if (i != j) {
      lazy[l].mask |= lazy[no].mask;
      lazy[r].mask |= lazy[no].mask;
      lazy[l].x = lazy[l].x * lazy[no].x % M;
      lazy[r].x = lazy[r].x * lazy[no].x % M;
    }
    lazy[no] = node(1, 0);
  }
}
void upd(int no, int i, int j, int a, int b, int v) {
  flush(no, i, j);
  if (i > j or i > b or j < a) return;
  if (a <= i and j <= b) {
    lazy[no] = node(v, Mask[v]);
    flush(no, i, j);
    return;
  }
  int mid = (i + j) >> 1, l = no << 1, r = no << 1 | 1;
  upd(l, i, mid, a, b, v);
  upd(r, mid + 1, j, a, b, v);
  tree[no] = tree[l] + tree[r];
}
node query(int no, int i, int j, int a, int b) {
  if (i > b or j < a) return node(1, 0);
  flush(no, i, j);
  if (a <= i and j <= b) {
    return tree[no];
  }
  int mid = (i + j) >> 1, l = no << 1, r = no << 1 | 1;
  return query(l, i, mid, a, b) + query(r, mid + 1, j, a, b);
}
int rev[P];
long long val[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int MAX = 0;
  vector<int> primes;
  for (int i = 2; i <= 300; i++) {
    if (is_prime(i)) {
      id[i] = MAX;
      rev[MAX] = i;
      val[MAX] = 1ll * (i - 1) * modpow(i, M - 2, M) % M;
      MAX++;
      primes.push_back(i);
    }
    for (int p : primes) {
      if (i % p == 0) {
        Mask[i] |= (1LL << id[p]);
      }
    }
  }
  int n, q;
  cin >> n >> q;
  for (int i = 1; i < (n + 1); ++i) {
    cin >> a[i];
  }
  build(1, 1, n);
  while (q--) {
    string s;
    cin >> s;
    if (s[0] == 'M') {
      int l, r, x;
      cin >> l >> r >> x;
      upd(1, 1, n, l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      node R = query(1, 1, n, l, r);
      long long x = R.x;
      long long mask = R.mask;
      for (int i = 0; i < MAX; i++) {
        if ((1LL << i) & mask) {
          x = x * val[i] % M;
        }
      }
      cout << x << "\n";
    }
  }
}
