#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 61);
const int inf = (1 << 30);
const int nmax = 4e5 + 50;
const int mod = 1e9 + 7;
using namespace std;
string s;
long long n, a[nmax], st[4 * nmax], i, lzy[4 * nmax], x, q, st1[4 * nmax],
    ms[4 * nmax], msk[nmax], m, ans, j, inv[100], l, r, sv[500], x1;
long long pr[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,
                  37,  41,  43,  47,  53,  59,  61,  67,  71,  73,  79,
                  83,  89,  97,  101, 103, 107, 109, 113, 127, 131, 137,
                  139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
                  197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257,
                  263, 269, 271, 277, 281, 283, 293};
long long pw(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 == 0) {
      a = (1LL * a * a) % mod;
      b /= 2;
    } else {
      res = (1LL * res * a) % mod;
      b -= 1;
    }
  }
  return res;
}
void build(int x, int l, int r) {
  if (l == r) {
    st[x] = a[l];
    st1[x] = msk[l];
    return;
  }
  int mid = (l + r) / 2;
  build(2 * x, l, mid);
  build(2 * x + 1, mid + 1, r);
  st[x] = st[2 * x] * st[2 * x + 1];
  st[x] %= mod;
  st1[x] = st1[2 * x] | st1[2 * x + 1];
}
void push(int nod, int l, int r) {
  if (!lzy[nod]) return;
  if (lzy[nod] != 1) st[nod] = (st[nod] * pw(lzy[nod], r - l + 1)) % mod;
  st1[nod] |= ms[nod];
  if (l != r) {
    if (lzy[nod] != 1) {
      lzy[nod * 2] *= lzy[nod];
      lzy[nod * 2 + 1] *= lzy[nod];
      lzy[nod * 2] %= mod;
      lzy[nod * 2 + 1] %= mod;
    }
    ms[nod * 2] |= ms[nod];
    ms[nod * 2 + 1] |= ms[nod];
  }
  lzy[nod] = 1;
}
void upd(int nod, int l, int r, int tl, int tr, long long v, long long m) {
  push(nod, l, r);
  if (tl <= l && r <= tr) {
    lzy[nod] = (lzy[nod] * v) % mod;
    ms[nod] |= m;
    push(nod, l, r);
    return;
  }
  int mid = (l + r) / 2;
  if (tl <= mid) upd(nod * 2, l, mid, tl, tr, v, m);
  if (mid < tr) upd(nod * 2 + 1, mid + 1, r, tl, tr, v, m);
  push(nod * 2, l, mid);
  push(nod * 2 + 1, mid + 1, r);
  st[nod] = st[nod * 2] * st[nod * 2 + 1];
  st[nod] %= mod;
  st1[nod] = st1[nod * 2] | st1[nod * 2 + 1];
}
pair<long long, long long> qry(int nod, int l, int r, int tl, int tr) {
  push(nod, l, r);
  if (tl <= l && r <= tr) return {st[nod], st1[nod]};
  int mid = (l + r) / 2;
  pair<long long, long long> vl, x;
  vl.first = 1, vl.second = 0;
  if (tl <= mid) {
    x = qry(nod * 2, l, mid, tl, tr);
    vl.first = (vl.first * x.first) % mod;
    vl.second |= x.second;
  }
  if (mid < tr) {
    x = qry(nod * 2 + 1, mid + 1, r, tl, tr);
    vl.first = (vl.first * x.first) % mod;
    vl.second |= x.second;
  }
  return vl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (j = 0; j < 62; j++) {
    inv[j] = pw(pr[j], mod - 2);
    sv[pr[j]] = j;
  }
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    for (j = 0; j < 62; j++)
      if (a[i] % pr[j] == 0) msk[i] |= (1LL << j);
  }
  for (i = 1; i <= 1600000; i++) lzy[i] = 1;
  build(1, 1, n);
  while (q--) {
    cin >> s;
    if (s[0] == 'M') {
      cin >> l >> r >> x;
      x1 = x, m = 0;
      for (j = 2; j * j <= x1; j++) {
        if (x1 % j == 0) {
          m |= (1LL << sv[j]);
          while (x1 % j == 0) x1 /= j;
        }
      }
      if (x1 > 1) m |= (1LL << sv[x1]);
      upd(1, 1, n, l, r, x, m);
    } else {
      cin >> l >> r;
      pair<long long, long long> p = qry(1, 1, n, l, r);
      ans = p.first;
      for (j = 0; j < 62; j++) {
        if (p.second & (1LL << j)) {
          ans = (ans * (1 - inv[j] + mod)) % mod;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 61);
const int inf = (1 << 30);
const int nmax = 4e5 + 50;
const int mod = 1e9 + 7;
using namespace std;
string s;
long long n, a[nmax], st[4 * nmax], i, lzy[4 * nmax], x, q, st1[4 * nmax],
    ms[4 * nmax], msk[nmax], m, ans, j, inv[100], l, r, sv[500], x1;
long long pr[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,
                  37,  41,  43,  47,  53,  59,  61,  67,  71,  73,  79,
                  83,  89,  97,  101, 103, 107, 109, 113, 127, 131, 137,
                  139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
                  197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257,
                  263, 269, 271, 277, 281, 283, 293};
long long pw(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 == 0) {
      a = (1LL * a * a) % mod;
      b /= 2;
    } else {
      res = (1LL * res * a) % mod;
      b -= 1;
    }
  }
  return res;
}
void build(int x, int l, int r) {
  if (l == r) {
    st[x] = a[l];
    st1[x] = msk[l];
    return;
  }
  int mid = (l + r) / 2;
  build(2 * x, l, mid);
  build(2 * x + 1, mid + 1, r);
  st[x] = st[2 * x] * st[2 * x + 1];
  st[x] %= mod;
  st1[x] = st1[2 * x] | st1[2 * x + 1];
}
void push(int nod, int l, int r) {
  if (!lzy[nod]) return;
  if (lzy[nod] != 1) st[nod] = (st[nod] * pw(lzy[nod], r - l + 1)) % mod;
  st1[nod] |= ms[nod];
  if (l != r) {
    if (lzy[nod] != 1) {
      lzy[nod * 2] *= lzy[nod];
      lzy[nod * 2 + 1] *= lzy[nod];
      lzy[nod * 2] %= mod;
      lzy[nod * 2 + 1] %= mod;
    }
    ms[nod * 2] |= ms[nod];
    ms[nod * 2 + 1] |= ms[nod];
  }
  lzy[nod] = 1;
}
void upd(int nod, int l, int r, int tl, int tr, long long v, long long m) {
  push(nod, l, r);
  if (tl <= l && r <= tr) {
    lzy[nod] = (lzy[nod] * v) % mod;
    ms[nod] |= m;
    push(nod, l, r);
    return;
  }
  int mid = (l + r) / 2;
  if (tl <= mid) upd(nod * 2, l, mid, tl, tr, v, m);
  if (mid < tr) upd(nod * 2 + 1, mid + 1, r, tl, tr, v, m);
  push(nod * 2, l, mid);
  push(nod * 2 + 1, mid + 1, r);
  st[nod] = st[nod * 2] * st[nod * 2 + 1];
  st[nod] %= mod;
  st1[nod] = st1[nod * 2] | st1[nod * 2 + 1];
}
pair<long long, long long> qry(int nod, int l, int r, int tl, int tr) {
  push(nod, l, r);
  if (tl <= l && r <= tr) return {st[nod], st1[nod]};
  int mid = (l + r) / 2;
  pair<long long, long long> vl, x;
  vl.first = 1, vl.second = 0;
  if (tl <= mid) {
    x = qry(nod * 2, l, mid, tl, tr);
    vl.first = (vl.first * x.first) % mod;
    vl.second |= x.second;
  }
  if (mid < tr) {
    x = qry(nod * 2 + 1, mid + 1, r, tl, tr);
    vl.first = (vl.first * x.first) % mod;
    vl.second |= x.second;
  }
  return vl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (j = 0; j < 62; j++) {
    inv[j] = pw(pr[j], mod - 2);
    sv[pr[j]] = j;
  }
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    for (j = 0; j < 62; j++)
      if (a[i] % pr[j] == 0) msk[i] |= (1LL << j);
  }
  for (i = 1; i <= 1600000; i++) lzy[i] = 1;
  build(1, 1, n);
  while (q--) {
    cin >> s;
    if (s[0] == 'M') {
      cin >> l >> r >> x;
      x1 = x, m = 0;
      for (j = 2; j * j <= x1; j++) {
        if (x1 % j == 0) {
          m |= (1LL << sv[j]);
          while (x1 % j == 0) x1 /= j;
        }
      }
      if (x1 > 1) m |= (1LL << sv[x1]);
      upd(1, 1, n, l, r, x, m);
    } else {
      cin >> l >> r;
      pair<long long, long long> p = qry(1, 1, n, l, r);
      ans = p.first;
      for (j = 0; j < 62; j++) {
        if (p.second & (1LL << j)) {
          ans = (ans * (1 - inv[j] + mod)) % mod;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}

```