#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long arr[4000000], arr2[4000000], lazy[4000000], lazy2[4000000], PWR[100];
vector<long long> v;
void sieve() {
  v.clear();
  for (long long i = 2; i <= 300; i++) {
    bool pr = true;
    for (long long j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) pr = false;
    }
    if (pr) v.push_back(i);
  }
}
long long tobin(long long x) {
  long long y = 0ll;
  for (long long i = 0; i < v.size(); i++) {
    if ((x % v[i]) == 0) {
      y |= (1ll << i);
    }
  }
  return y;
}
void build(long long idx, long long a, long long b) {
  arr[idx] = 1ll;
  lazy[idx] = 1ll;
  arr2[idx] = 0ll;
  lazy2[idx] = 0ll;
  if (a == b) {
    cin >> arr[idx];
    arr2[idx] = tobin(arr[idx]);
    return;
  }
  build(idx * 2, a, (a + b) / 2);
  build(idx * 2 + 1, (a + b) / 2 + 1, b);
  arr[idx] = (arr[idx * 2] * arr[idx * 2 + 1]) % MOD;
  arr2[idx] = (arr2[idx * 2] | arr2[idx * 2 + 1]);
  return;
}
long long pwr(long long x, long long p) {
  if (p == 0ll || x == 1ll) return 1ll;
  if (p == 1ll || x == 0ll) return x;
  long long a = pwr((x * x) % MOD, p / 2ll);
  if (p % 2ll == 0ll) return a;
  return (x * a) % MOD;
}
void propag(long long idx, long long a, long long b) {
  arr[idx] = (arr[idx] * pwr(lazy[idx], (b - a + 1ll))) % MOD;
  lazy[idx * 2] = (lazy[idx * 2] * lazy[idx]) % MOD;
  lazy[idx * 2 + 1] = (lazy[idx * 2 + 1] * lazy[idx]) % MOD;
  lazy[idx] = 1ll;
}
void propag2(long long idx) {
  arr2[idx] = (arr2[idx] | lazy2[idx]);
  lazy2[idx * 2] = (lazy2[idx * 2] | lazy2[idx]);
  lazy2[idx * 2 + 1] = (lazy2[idx * 2 + 1] | lazy2[idx]);
  lazy2[idx] = 0ll;
}
void update(long long idx, long long a, long long b, long long l, long long r,
            long long x, long long y) {
  propag(idx, a, b);
  propag2(idx);
  if (b < l || a > r) return;
  if (l <= a && b <= r) {
    lazy[idx] = x;
    propag(idx, a, b);
    lazy2[idx] = y;
    propag2(idx);
    return;
  }
  update(idx * 2, a, (a + b) / 2, l, r, x, y);
  update(idx * 2 + 1, (a + b) / 2 + 1, b, l, r, x, y);
  arr[idx] = (arr[idx * 2] * arr[idx * 2 + 1]) % MOD;
  arr2[idx] = (arr2[idx * 2] | arr2[idx * 2 + 1]);
}
long long query(long long idx, long long a, long long b, long long l,
                long long r) {
  propag(idx, a, b);
  if (b < l || a > r) return 1ll;
  if (l <= a && b <= r) {
    return arr[idx];
  }
  return (query(idx * 2, a, (a + b) / 2, l, r) *
          query(idx * 2 + 1, (a + b) / 2 + 1, b, l, r)) %
         MOD;
}
long long query2(long long idx, long long a, long long b, long long l,
                 long long r) {
  propag2(idx);
  if (b < l || a > r) return 0ll;
  if (l <= a && b <= r) {
    return arr2[idx];
  }
  return (query2(idx * 2, a, (a + b) / 2, l, r) |
          query2(idx * 2 + 1, (a + b) / 2 + 1, b, l, r));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  sieve();
  long long n, q;
  cin >> n >> q;
  for (int i = 0; i < v.size(); i++) {
    PWR[i] = ((v[i] - 1ll) * pwr(v[i], MOD - 2ll)) % MOD;
  }
  build(1, 1, n);
  while (q--) {
    string tipe;
    cin >> tipe;
    if (tipe[0] == 'T') {
      long long l, r;
      cin >> l >> r;
      long long ans = query(1, 1, n, l, r);
      long long bin = query2(1, 1, n, l, r);
      for (long long i = 0; i < v.size(); i++) {
        if ((bin & (1ll << i)) > 0ll) {
          ans = (ans * PWR[i]) % MOD;
        }
      }
      cout << ans << "\n";
    } else {
      long long l, r, x;
      cin >> l >> r >> x;
      long long y = tobin(x);
      update(1, 1, n, l, r, x, y);
    }
  }
  return 0;
}
