#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int maxn = 400000 + 10;
int cnt, n, q, x, l, r;
int sum[63][maxn], ssum[63][maxn];
long long inv[301], mult[301];
int prime[301];
bool vis[301];
vector<int> fac;
long long num[maxn << 2], lazy[maxn << 2];
char cmd[20];
int Index_of_prime[301];
void Prime(int n) {
  for (int i = 2; i <= n; ++i) {
    if (!vis[i]) {
      Index_of_prime[i] = cnt;
      prime[cnt++] = i;
    }
    for (int j = 0; j < cnt && i <= n / prime[j]; ++j) {
      int k = i * prime[j];
      vis[k] = true;
      if (i % prime[j] == 0) {
        break;
      }
    }
  }
}
void get_fac(int n, vector<int> &fac) {
  fac.clear();
  for (int i = 0; i < cnt && prime[i] <= n / prime[i]; ++i) {
    if (n % prime[i] == 0) {
      fac.push_back(prime[i]);
      while (n % prime[i] == 0) {
        n /= prime[i];
      }
    }
  }
  if (n != 1) {
    fac.push_back(n);
  }
}
void Prepare_C() {
  inv[1] = 1;
  for (int i = 2; i <= 300; ++i) {
    inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
  }
}
int lowbit(int x) { return x & (-x); }
void update(int *sum, int *ssum, int Index, int x) {
  int tmp = Index;
  while (tmp <= n) {
    sum[tmp] += x;
    ssum[tmp] += (long long)x * Index;
    tmp += lowbit(tmp);
  }
}
long long query(int *sum, int *ssum, int Index) {
  long long ret = 0;
  int tmp = Index;
  while (tmp != 0) {
    ret += sum[tmp] * (Index + 1) - ssum[tmp];
    tmp -= lowbit(tmp);
  }
  return ret;
}
void push_up(int rt) { num[rt] = num[rt << 1] * num[rt << 1 | 1] % MOD; }
long long fast_pow(long long res, long long n) {
  long long ans;
  for (ans = 1; n != 0; n >>= 1) {
    if ((n & 1) == 1) {
      ans = ans * res % MOD;
    }
    res = res * res % MOD;
  }
  return ans;
}
void push_down(int rt, int len) {
  if (lazy[rt] != 1) {
    lazy[rt << 1] = lazy[rt << 1] * lazy[rt] % MOD;
    lazy[rt << 1 | 1] = lazy[rt << 1 | 1] * lazy[rt] % MOD;
    num[rt << 1] = fast_pow(lazy[rt], len - (len >> 1)) * num[rt << 1] % MOD;
    num[rt << 1 | 1] = fast_pow(lazy[rt], len >> 1) * num[rt << 1 | 1] % MOD;
    lazy[rt] = 1;
  }
}
void build(int l, int r, int rt) {
  lazy[rt] = 1;
  num[rt] = 1;
  if (l == r) {
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
}
void update(int L, int R, long long tmp, int l, int r, int rt) {
  if (L <= l && r <= R) {
    lazy[rt] = lazy[rt] * tmp % MOD;
    num[rt] = num[rt] * fast_pow(tmp, r - l + 1) % MOD;
    return;
  }
  push_down(rt, r - l + 1);
  int m = (l + r) >> 1;
  if (L <= m) {
    update(L, R, tmp, l, m, rt << 1);
  }
  if (m < R) {
    update(L, R, tmp, m + 1, r, rt << 1 | 1);
  }
  push_up(rt);
}
long long query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) {
    return num[rt];
  }
  push_down(rt, r - l + 1);
  int m = (l + r) >> 1;
  long long ret = 1;
  if (L <= m) {
    ret = ret * query(L, R, l, m, rt << 1) % MOD;
  }
  if (m < R) {
    ret = ret * query(L, R, m + 1, r, rt << 1 | 1) % MOD;
  }
  return ret;
}
void update(int l, int r, int x) {
  update(l, r, x, 1, n, 1);
  get_fac(x, fac);
  int len = fac.size();
  for (int i = 0; i < len; ++i) {
    update(sum[Index_of_prime[fac[i]]], ssum[Index_of_prime[fac[i]]], l, 1);
    update(sum[Index_of_prime[fac[i]]], ssum[Index_of_prime[fac[i]]], r + 1,
           -1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  Prepare_C();
  Prime(300);
  for (int i = 1; i <= 300; ++i) {
    mult[i] = (i - 1) * inv[i] % MOD;
  }
  while (scanf("%d%d", &n, &q) != EOF) {
    for (int i = 0; i <= 62; ++i) {
      memset(sum[i] + 1, 0, sizeof(int) * n);
    }
    build(1, n, 1);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &x);
      update(i, i, x);
    }
    while (q--) {
      scanf("%s", cmd);
      if (cmd[0] == 'M') {
        scanf("%d%d%d", &l, &r, &x);
        update(l, r, x);
      } else {
        scanf("%d%d", &l, &r);
        long long ans = query(l, r, 1, n, 1);
        for (int i = 0; i <= 62; ++i) {
          if (query(sum[i], ssum[i], l - 1) != query(sum[i], ssum[i], r)) {
            ans = ans * mult[prime[i]] % MOD;
          }
        }
        printf("%I64d\n", ans);
      }
    }
  }
  return 0;
}
