#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int num;
bool vis[310];
long long pri[65];
long long factor[310];
long long inv[65];
long long ans1, ans2;
struct Node {
  int left, right;
  long long val;
  long long in;
  long long f, inf;
} node[400010 << 2];
long long PowerMod(long long a, long long b, long long c) {
  long long ans = 1;
  long long k;
  k = a;
  k = k % c;
  while (b > 0) {
    if (b & 1) ans = (ans * k) % c;
    b >>= 1;
    k = (k * k) % c;
  }
  return ans;
}
void init() {
  for (long long i = 2; i <= 300; i++) {
    if (vis[i] == false) pri[num++] = i;
    for (long long j = 0; j < num && i * pri[j] <= 300; j++) {
      vis[i * pri[j]] = true;
      if (i % pri[j] == 0) break;
    }
  }
  for (int i = 0; i < num; i++) inv[i] = PowerMod(pri[i], MOD - 2, MOD);
  for (int i = 2; i <= 300; i++) {
    long long temp = i;
    for (int j = 0; j < num && pri[j] <= temp; j++) {
      if (temp % pri[j] == 0) {
        factor[i] |= 1ll << j;
        while (temp % pri[j] == 0) temp /= pri[j];
      }
    }
  }
}
void build(int l, int r, int id) {
  node[id].left = l;
  node[id].right = r;
  node[id].in = 0;
  node[id].f = 1;
  node[id].inf = 0;
  if (l == r) {
    scanf("%lld", &node[id].val);
    node[id].in |= factor[node[id].val];
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, id << 1);
  build(m + 1, r, id << 1 | 1);
  node[id].val = node[id << 1].val * node[id << 1 | 1].val % MOD;
  node[id].in = node[id << 1].in | node[id << 1 | 1].in;
}
void down(int id) {
  int l1 = node[id << 1].left, r1 = node[id << 1].right;
  int l2 = node[id << 1 | 1].left, r2 = node[id << 1 | 1].right;
  node[id << 1].f = node[id << 1].f * node[id].f % MOD;
  node[id << 1 | 1].f = node[id << 1 | 1].f * node[id].f % MOD;
  node[id << 1].val =
      node[id << 1].val * PowerMod(node[id].f, r1 - l1 + 1, MOD) % MOD;
  node[id << 1 | 1].val =
      node[id << 1 | 1].val * PowerMod(node[id].f, r2 - l2 + 1, MOD) % MOD;
  node[id << 1].inf |= node[id].inf;
  node[id << 1 | 1].inf |= node[id].inf;
  node[id << 1].in |= node[id].inf;
  node[id << 1 | 1].in |= node[id].inf;
  node[id].f = 1;
  node[id].inf = 0;
}
void query(int L, int R, int id) {
  int l = node[id].left, r = node[id].right;
  if (l >= L && r <= R) {
    ans1 = ans1 * node[id].val % MOD;
    ans2 |= node[id].in;
    return;
  }
  if (node[id].f != 1 || node[id].inf != 0) down(id);
  int m = (l + r) >> 1;
  if (L <= m) query(L, R, id << 1);
  if (R > m) query(L, R, id << 1 | 1);
}
void update(int L, int R, long long x, int id) {
  int l = node[id].left, r = node[id].right;
  if (l >= L && r <= R) {
    node[id].val = node[id].val * PowerMod(x, r - l + 1, MOD) % MOD;
    node[id].in |= factor[x];
    node[id].f = node[id].f * x % MOD;
    node[id].inf |= factor[x];
    return;
  }
  if (node[id].f != 1 || node[id].inf != 0) down(id);
  int m = (l + r) >> 1;
  if (L <= m) update(L, R, x, id << 1);
  if (R > m) update(L, R, x, id << 1 | 1);
  node[id].val = node[id << 1].val * node[id << 1 | 1].val % MOD;
  node[id].in = node[id << 1].in | node[id << 1 | 1].in;
}
int main() {
  init();
  int n, q, x, y;
  long long z;
  char s[10];
  scanf("%d%d", &n, &q);
  build(1, n, 1);
  scanf("%d", &q);
  while (q--) {
    scanf("%s", s);
    if (s[0] == 'M') {
      scanf("%d%d%lld", &x, &y, &z);
      update(x, y, z, 1);
    } else if (s[0] == 'T') {
      scanf("%d%d", &x, &y);
      ans1 = 1;
      ans2 = 0;
      query(x, y, 1);
      if (ans1 == 1 && ans2 == 0) {
        printf("1\n");
        continue;
      }
      long long ans = ans1;
      for (int i = 0; i < 62; i++) {
        if (ans2 >> i & 1) ans = ans * (pri[i] - 1) % MOD * inv[i] % MOD;
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
