#include <bits/stdc++.h>
using namespace std;
inline long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long bp(long long b, long long p) {
  long long ac = 1;
  while (p > 0) {
    if (p & 1) {
      ac = mul(ac, b);
    }
    b = mul(b, b);
    p /= 2;
  }
  return ac;
}
int pl[300];
int rpl[300];
bool prm(int n) {
  if (n < 2) {
    return false;
  }
  if (n <= 3) {
    return true;
  }
  if (!(n % 2) || !(n % 3)) {
    return false;
  }
  for (int i = 5; i * i <= n; i += 6) {
    if (!(n % i) || !(n % (i + 2))) {
      return false;
    }
  }
  return true;
}
long long dpf[400];
long long fac(int b) {
  long long og = b;
  if (b <= 300 && dpf[b] != -1) {
    return dpf[b];
  }
  long long res = 0;
  for (int id = 0; rpl[id] * rpl[id] <= b; id++) {
    while (!(b % rpl[id])) {
      b /= (rpl[id]);
      res |= (1LL << id);
    }
  }
  if (b > 1) {
    res |= (1LL << pl[b]);
  }
  if (og <= 300) {
    dpf[og] = res;
  }
  return res;
}
void init() {
  memset(pl, -1, sizeof(pl));
  int ct = 0;
  for (int i = 0; i < 300; i++) {
    if (prm(i)) {
      pl[i] = ct;
      rpl[ct] = i;
      ct++;
    }
  }
}
long long dpi[400];
long long inv(long long v) {
  if (dpi[v] != -1) {
    return dpi[v];
  }
  return dpi[v] = bp(v, 1000000007 - 2);
}
class ST {
 private:
  vector<long long> bs, st, A, lzb, lzs;
  int n;
  int lf(int p) { return p << 1; }
  int rt(int p) { return 1 + (p << 1); }
  void build(int p, int l, int r) {
    if (l == r) {
      st[p] = A[l];
      bs[p] = fac(A[l]);
      return;
    }
    int m = (l + r) / 2;
    build(lf(p), l, m);
    build(rt(p), m + 1, r);
    st[p] = mul(st[lf(p)], st[rt(p)]);
    bs[p] = bs[lf(p)] | bs[rt(p)];
  }
  void upS(int p, int l, int r, int i, int j, long long v) {
    if (lzs[p] != 1) {
      st[p] = mul(st[p], bp(lzs[p], r - l + 1));
      if (l != r) {
        lzs[lf(p)] = mul(lzs[lf(p)], lzs[p]);
        lzs[rt(p)] = mul(lzs[rt(p)], lzs[p]);
      }
      lzs[p] = 1;
    }
    if (l > j || r < i) {
      return;
    }
    if (l == r) {
      st[p] = mul(st[p], v);
      return;
    }
    if (l >= i && r <= j) {
      st[p] = mul(st[p], bp(v, r - l + 1));
      lzs[lf(p)] = mul(lzs[lf(p)], v);
      lzs[rt(p)] = mul(lzs[rt(p)], v);
      return;
    }
    int m = (l + r) / 2;
    upS(lf(p), l, m, i, j, v);
    upS(rt(p), m + 1, r, i, j, v);
    st[p] = mul(st[lf(p)], st[rt(p)]);
  }
  void upB(int p, int l, int r, int i, int j, long long v) {
    if (lzb[p] != 0) {
      bs[p] |= lzb[p];
      if (l != r) {
        lzb[lf(p)] |= lzb[p];
        lzb[rt(p)] |= lzb[p];
      }
      lzb[p] = 0;
    }
    if (l > j || r < i) {
      return;
    }
    if (l == r) {
      bs[p] |= v;
      return;
    }
    if (l >= i && r <= j) {
      bs[p] |= v;
      lzb[lf(p)] |= v;
      lzb[rt(p)] |= v;
      return;
    }
    int m = (l + r) / 2;
    upB(lf(p), l, m, i, j, v);
    upB(rt(p), m + 1, r, i, j, v);
    bs[p] = bs[lf(p)] | bs[rt(p)];
  }
  long long cinv(long long bv) {
    long long res = 1;
    for (int i = 0; i < 62; i++) {
      if ((1LL << i) & bv) {
        res = mul(res, inv(rpl[i]));
        res = mul(res, rpl[i] - 1);
      }
    }
    return res;
  }
  pair<long long, long long> tot(int p, int l, int r, int i, int j) {
    if (l > j || r < i) {
      return make_pair(1, 0);
    }
    if (lzs[p] != 1) {
      st[p] = mul(st[p], bp(lzs[p], r - l + 1));
      if (l != r) {
        lzs[lf(p)] = mul(lzs[lf(p)], lzs[p]);
        lzs[rt(p)] = mul(lzs[rt(p)], lzs[p]);
      }
      lzs[p] = 1;
    }
    if (lzb[p] != 0) {
      bs[p] |= lzb[p];
      if (l != r) {
        lzb[lf(p)] |= lzb[p];
        lzb[rt(p)] |= lzb[p];
      }
      lzb[p] = 0;
    }
    if (l >= i && r <= j) {
      return make_pair(st[p], bs[p]);
    }
    if (l == r) {
      return make_pair(st[p], bs[p]);
    }
    pair<long long, long long> rl, rr;
    int m = (l + r) / 2;
    rl = tot(lf(p), l, m, i, j);
    rr = tot(rt(p), m + 1, r, i, j);
    pair<long long, long long> res =
        make_pair(mul(rr.first, rl.first), (rl.second | rr.second));
    return make_pair(mul(rr.first, rl.first), (rl.second | rr.second));
  }

 public:
  ST(vector<long long> _A) {
    A = _A;
    n = A.size();
    st.assign(4 * n, 1);
    bs.assign(4 * n, 0);
    lzb.assign(4 * n, 0);
    lzs.assign(4 * n, 1);
    build(1, 0, n - 1);
  }
  void mult(int i, int j, int val) {
    long long bv = 0;
    bv |= fac(val);
    upB(1, 0, n - 1, i, j, bv);
    upS(1, 0, n - 1, i, j, val);
  }
  long long tot(int i, int j) {
    pair<long long, long long> pre = tot(1, 0, n - 1, i, j);
    return mul(pre.first, cinv(pre.second));
  }
};
int main() {
  ios::sync_with_stdio(0);
  memset(dpf, -1, sizeof(dpf));
  memset(dpi, -1, sizeof(dpi));
  int n, q;
  cin >> n >> q;
  vector<long long> v;
  init();
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    v.push_back(t);
  }
  ST st(v);
  char s[300];
  while (q--) {
    int l, r;
    cin >> s >> l >> r;
    l--;
    r--;
    if (s[0] == 'M') {
      int mv;
      cin >> mv;
      st.mult(l, r, mv);
    } else {
      long long rv = st.tot(l, r);
      cout << rv % 1000000007 << '\n';
    }
  }
}

### Prompt

Develop a solution in cpp to the problem described below:

You are given an array a_1, a_2, …, a_n.

You need to perform q queries of the following two types:

  1. "MULTIPLY l r x" — for every i (l ≤ i ≤ r) multiply a_i by x.
  2. "TOTIENT l r" — print \varphi(∏ _{i=l}^{r} a_i) taken modulo 10^9+7, where \varphi denotes Euler's totient function. 



The [Euler's totient function](http://gg.gg/euler_totient) of a positive integer n (denoted as \varphi(n)) is the number of integers x (1 ≤ x ≤ n) such that \gcd(n,x) = 1.

Input

The first line contains two integers n and q (1 ≤ n ≤ 4 ⋅ 10^5, 1 ≤ q ≤ 2 ⋅ 10^5) — the number of elements in array a and the number of queries.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300) — the elements of array a.

Then q lines follow, describing queries in the format given in the statement.

  1. "MULTIPLY l r x" (1 ≤ l ≤ r ≤ n, 1 ≤ x ≤ 300) — denotes a multiplication query.
  2. "TOTIENT l r" (1 ≤ l ≤ r ≤ n) — denotes a query on the value of Euler's totient function. 



It is guaranteed that there is at least one "TOTIENT" query.

Output

For each "TOTIENT" query, print the answer to it.

Example

Input

4 4
5 9 1 2
TOTIENT 3 3
TOTIENT 3 4
MULTIPLY 4 4 3
TOTIENT 4 4


Output

1
1
2

Note

In the first example, \varphi(1) = 1 for the first query, \varphi(2) = 1 for the second query and \varphi(6) = 2 for the third one.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long bp(long long b, long long p) {
  long long ac = 1;
  while (p > 0) {
    if (p & 1) {
      ac = mul(ac, b);
    }
    b = mul(b, b);
    p /= 2;
  }
  return ac;
}
int pl[300];
int rpl[300];
bool prm(int n) {
  if (n < 2) {
    return false;
  }
  if (n <= 3) {
    return true;
  }
  if (!(n % 2) || !(n % 3)) {
    return false;
  }
  for (int i = 5; i * i <= n; i += 6) {
    if (!(n % i) || !(n % (i + 2))) {
      return false;
    }
  }
  return true;
}
long long dpf[400];
long long fac(int b) {
  long long og = b;
  if (b <= 300 && dpf[b] != -1) {
    return dpf[b];
  }
  long long res = 0;
  for (int id = 0; rpl[id] * rpl[id] <= b; id++) {
    while (!(b % rpl[id])) {
      b /= (rpl[id]);
      res |= (1LL << id);
    }
  }
  if (b > 1) {
    res |= (1LL << pl[b]);
  }
  if (og <= 300) {
    dpf[og] = res;
  }
  return res;
}
void init() {
  memset(pl, -1, sizeof(pl));
  int ct = 0;
  for (int i = 0; i < 300; i++) {
    if (prm(i)) {
      pl[i] = ct;
      rpl[ct] = i;
      ct++;
    }
  }
}
long long dpi[400];
long long inv(long long v) {
  if (dpi[v] != -1) {
    return dpi[v];
  }
  return dpi[v] = bp(v, 1000000007 - 2);
}
class ST {
 private:
  vector<long long> bs, st, A, lzb, lzs;
  int n;
  int lf(int p) { return p << 1; }
  int rt(int p) { return 1 + (p << 1); }
  void build(int p, int l, int r) {
    if (l == r) {
      st[p] = A[l];
      bs[p] = fac(A[l]);
      return;
    }
    int m = (l + r) / 2;
    build(lf(p), l, m);
    build(rt(p), m + 1, r);
    st[p] = mul(st[lf(p)], st[rt(p)]);
    bs[p] = bs[lf(p)] | bs[rt(p)];
  }
  void upS(int p, int l, int r, int i, int j, long long v) {
    if (lzs[p] != 1) {
      st[p] = mul(st[p], bp(lzs[p], r - l + 1));
      if (l != r) {
        lzs[lf(p)] = mul(lzs[lf(p)], lzs[p]);
        lzs[rt(p)] = mul(lzs[rt(p)], lzs[p]);
      }
      lzs[p] = 1;
    }
    if (l > j || r < i) {
      return;
    }
    if (l == r) {
      st[p] = mul(st[p], v);
      return;
    }
    if (l >= i && r <= j) {
      st[p] = mul(st[p], bp(v, r - l + 1));
      lzs[lf(p)] = mul(lzs[lf(p)], v);
      lzs[rt(p)] = mul(lzs[rt(p)], v);
      return;
    }
    int m = (l + r) / 2;
    upS(lf(p), l, m, i, j, v);
    upS(rt(p), m + 1, r, i, j, v);
    st[p] = mul(st[lf(p)], st[rt(p)]);
  }
  void upB(int p, int l, int r, int i, int j, long long v) {
    if (lzb[p] != 0) {
      bs[p] |= lzb[p];
      if (l != r) {
        lzb[lf(p)] |= lzb[p];
        lzb[rt(p)] |= lzb[p];
      }
      lzb[p] = 0;
    }
    if (l > j || r < i) {
      return;
    }
    if (l == r) {
      bs[p] |= v;
      return;
    }
    if (l >= i && r <= j) {
      bs[p] |= v;
      lzb[lf(p)] |= v;
      lzb[rt(p)] |= v;
      return;
    }
    int m = (l + r) / 2;
    upB(lf(p), l, m, i, j, v);
    upB(rt(p), m + 1, r, i, j, v);
    bs[p] = bs[lf(p)] | bs[rt(p)];
  }
  long long cinv(long long bv) {
    long long res = 1;
    for (int i = 0; i < 62; i++) {
      if ((1LL << i) & bv) {
        res = mul(res, inv(rpl[i]));
        res = mul(res, rpl[i] - 1);
      }
    }
    return res;
  }
  pair<long long, long long> tot(int p, int l, int r, int i, int j) {
    if (l > j || r < i) {
      return make_pair(1, 0);
    }
    if (lzs[p] != 1) {
      st[p] = mul(st[p], bp(lzs[p], r - l + 1));
      if (l != r) {
        lzs[lf(p)] = mul(lzs[lf(p)], lzs[p]);
        lzs[rt(p)] = mul(lzs[rt(p)], lzs[p]);
      }
      lzs[p] = 1;
    }
    if (lzb[p] != 0) {
      bs[p] |= lzb[p];
      if (l != r) {
        lzb[lf(p)] |= lzb[p];
        lzb[rt(p)] |= lzb[p];
      }
      lzb[p] = 0;
    }
    if (l >= i && r <= j) {
      return make_pair(st[p], bs[p]);
    }
    if (l == r) {
      return make_pair(st[p], bs[p]);
    }
    pair<long long, long long> rl, rr;
    int m = (l + r) / 2;
    rl = tot(lf(p), l, m, i, j);
    rr = tot(rt(p), m + 1, r, i, j);
    pair<long long, long long> res =
        make_pair(mul(rr.first, rl.first), (rl.second | rr.second));
    return make_pair(mul(rr.first, rl.first), (rl.second | rr.second));
  }

 public:
  ST(vector<long long> _A) {
    A = _A;
    n = A.size();
    st.assign(4 * n, 1);
    bs.assign(4 * n, 0);
    lzb.assign(4 * n, 0);
    lzs.assign(4 * n, 1);
    build(1, 0, n - 1);
  }
  void mult(int i, int j, int val) {
    long long bv = 0;
    bv |= fac(val);
    upB(1, 0, n - 1, i, j, bv);
    upS(1, 0, n - 1, i, j, val);
  }
  long long tot(int i, int j) {
    pair<long long, long long> pre = tot(1, 0, n - 1, i, j);
    return mul(pre.first, cinv(pre.second));
  }
};
int main() {
  ios::sync_with_stdio(0);
  memset(dpf, -1, sizeof(dpf));
  memset(dpi, -1, sizeof(dpi));
  int n, q;
  cin >> n >> q;
  vector<long long> v;
  init();
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    v.push_back(t);
  }
  ST st(v);
  char s[300];
  while (q--) {
    int l, r;
    cin >> s >> l >> r;
    l--;
    r--;
    if (s[0] == 'M') {
      int mv;
      cin >> mv;
      st.mult(l, r, mv);
    } else {
      long long rv = st.tot(l, r);
      cout << rv % 1000000007 << '\n';
    }
  }
}

```