#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[400001];
struct node {
  long long ans;
  long long p;
} tree[4 * 400001], lazy[4 * 400001], dp[301];
vector<int> prime;
long long power(int x, int n) {
  if (n == 0) return 1;
  if (n & 1) {
    return (x * power(x, n - 1)) % 1000000007;
  }
  long long y = power(x, n / 2);
  return (y * y) % 1000000007;
}
long long d, x, y;
void extendedEuclid(long long A, long long B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    long long temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
long long modInverse(long long A, long long M) {
  extendedEuclid(A, M);
  return (x % M + M) % M;
}
void help(int n, int i) {
  long long p = 0;
  for (long long i = 0; i < prime.size(); i++) {
    if (n % prime[i] == 0) p = p | (1ll << i);
  }
  dp[i].ans = n;
  dp[i].p = p;
}
void combine(struct node &n, struct node &left, struct node &right) {
  n.ans = (left.ans * right.ans) % 1000000007;
  n.p = left.p | right.p;
}
void build(int node, int start, int end) {
  if (start == end) {
    tree[node] = dp[a[start]];
  } else {
    int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    combine(tree[node], tree[2 * node], tree[2 * node + 1]);
  }
}
void updateRange(int node, int start, int end, int l, int r, int val) {
  if (lazy[node].p != 0) {
    long long temp = power(lazy[node].ans, end - start + 1);
    tree[node].ans = (tree[node].ans * temp) % 1000000007;
    tree[node].p = tree[node].p | lazy[node].p;
    if (start != end) {
      lazy[node * 2].ans = (lazy[node * 2].ans * lazy[node].ans) % 1000000007;
      lazy[node * 2 + 1].ans =
          (lazy[node * 2 + 1].ans * lazy[node].ans) % 1000000007;
      lazy[node * 2].p = lazy[node * 2].p | lazy[node].p;
      lazy[node * 2 + 1].p = lazy[node * 2 + 1].p | lazy[node].p;
    }
    lazy[node].ans = 1;
    lazy[node].p = 0;
  }
  if (start > end or start > r or end < l) return;
  if (start >= l and end <= r) {
    long long temp = power(dp[val].ans, end - start + 1);
    tree[node].ans = (tree[node].ans * temp) % 1000000007;
    tree[node].p = tree[node].p | dp[val].p;
    if (start != end) {
      lazy[node * 2].ans = (lazy[node * 2].ans * dp[val].ans) % 1000000007;
      lazy[node * 2 + 1].ans =
          (lazy[node * 2 + 1].ans * dp[val].ans) % 1000000007;
      lazy[node * 2].p = lazy[node * 2].p | dp[val].p;
      lazy[node * 2 + 1].p = lazy[node * 2 + 1].p | dp[val].p;
    }
    return;
  }
  int mid = (start + end) / 2;
  updateRange(node * 2, start, mid, l, r, val);
  updateRange(node * 2 + 1, mid + 1, end, l, r, val);
  combine(tree[node], tree[node * 2], tree[node * 2 + 1]);
}
struct node queryRange(int node, int start, int end, int l, int r) {
  if (start > end or start > r or end < l) {
    struct node temp;
    temp.ans = 1;
    temp.p = 0;
    return temp;
  }
  if (lazy[node].p != 0) {
    long long temp = power(lazy[node].ans, end - start + 1);
    tree[node].ans = (tree[node].ans * temp) % 1000000007;
    tree[node].p = tree[node].p | lazy[node].p;
    if (start != end) {
      lazy[node * 2].ans = (lazy[node * 2].ans * lazy[node].ans) % 1000000007;
      lazy[node * 2 + 1].ans =
          (lazy[node * 2 + 1].ans * lazy[node].ans) % 1000000007;
      lazy[node * 2].p = lazy[node * 2].p | lazy[node].p;
      lazy[node * 2 + 1].p = lazy[node * 2 + 1].p | lazy[node].p;
    }
    lazy[node].ans = 1;
    lazy[node].p = 0;
  }
  if (start >= l and end <= r) return tree[node];
  int mid = (start + end) / 2;
  struct node temp;
  struct node p1 = queryRange(node * 2, start, mid, l, r);
  struct node p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
  combine(temp, p1, p2);
  return temp;
}
long long func(struct node &n) {
  long long ans = n.ans;
  for (long long i = 0; i < prime.size(); i++) {
    if (n.p & (1ll << i)) {
      long long temp =
          ((prime[i] - 1) * modInverse(prime[i], 1000000007)) % 1000000007;
      ans = (ans * temp) % 1000000007;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2; i <= 300; i++) {
    bool isPrime = true;
    for (int j = 2; j <= sqrt(i); j++) {
      if (i % j == 0) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) prime.push_back(i);
  }
  for (int i = 1; i <= 300; i++) help(i, i);
  for (int i = 0; i < 4 * 400001; i++) {
    tree[i].ans = 1;
    tree[i].p = 0;
    lazy[i].ans = 1;
    lazy[i].p = 0;
  }
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build(1, 1, n);
  while (q--) {
    string s;
    int l, r, x;
    cin >> s;
    if (s[0] == 'M') {
      cin >> l >> r >> x;
      updateRange(1, 1, n, l, r, x);
    } else {
      cin >> l >> r;
      struct node temp = queryRange(1, 1, n, l, r);
      cout << func(temp) << "\n";
    }
  }
  return 0;
}
