#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T neg = 1;
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= neg;
}
const int MAXV = 300;
const int MAXN = 4e5;
const int MOD = 1e9 + 7;
int qpow(int x, int e) {
  int ret = 1;
  for (; e; e >>= 1, x = 1ll * x * x % MOD)
    if (e & 1) ret = 1ll * ret * x % MOD;
  return ret;
}
bitset<MAXV + 5> vis;
int pr[MAXV / 3 + 5], prcnt = 0, phi[MAXV + 5];
void sieve(int n) {
  phi[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pr[++prcnt] = i;
    for (int j = 1; pr[j] * i <= n && j <= prcnt; j++) {
      vis[pr[j] * i] = 1;
      if (i % pr[j] == 0) break;
    }
  }
}
int n, qu, a[MAXN + 5];
struct node {
  int l, r, mul, lz;
  long long msk, tag_msk;
} s[MAXN * 4 + 5];
void pushup(int k) {
  s[k].mul = 1ll * s[k << 1].mul * s[k << 1 | 1].mul % MOD;
  s[k].msk = s[k << 1].msk | s[k << 1 | 1].msk;
}
void build(int k, int l, int r) {
  s[k].l = l;
  s[k].r = r;
  s[k].lz = 1;
  if (l == r) {
    s[k].mul = a[l];
    for (int i = 1; i <= prcnt; i++)
      if (a[l] % pr[i] == 0) s[k].msk |= 1ll << (i - 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  pushup(k);
}
void pushdown(int k) {
  if (s[k].lz != 1) {
    s[k << 1].mul = 1ll * s[k << 1].mul *
                    qpow(s[k].lz, s[k << 1].r - s[k << 1].l + 1) % MOD;
    s[k << 1].lz = 1ll * s[k << 1].lz * s[k].lz % MOD;
    s[k << 1].msk = s[k << 1].msk | s[k].tag_msk;
    s[k << 1].tag_msk = s[k << 1].tag_msk | s[k].tag_msk;
    s[k << 1 | 1].mul = 1ll * s[k << 1 | 1].mul *
                        qpow(s[k].lz, s[k << 1 | 1].r - s[k << 1 | 1].l + 1) %
                        MOD;
    s[k << 1 | 1].lz = 1ll * s[k << 1 | 1].lz * s[k].lz % MOD;
    s[k << 1 | 1].msk = s[k << 1 | 1].msk | s[k].tag_msk;
    s[k << 1 | 1].tag_msk = s[k << 1 | 1].tag_msk | s[k].tag_msk;
    s[k].lz = 1;
    s[k].tag_msk = 0;
  }
}
void modify(int k, int l, int r, int x, long long y) {
  if (l <= s[k].l && s[k].r <= r) {
    s[k].mul = 1ll * s[k].mul * qpow(x, s[k].r - s[k].l + 1) % MOD;
    s[k].msk |= y;
    s[k].lz = 1ll * s[k].lz * x % MOD;
    s[k].tag_msk |= y;
    return;
  }
  pushdown(k);
  int mid = (s[k].l + s[k].r) >> 1;
  if (r <= mid)
    modify(k << 1, l, r, x, y);
  else if (l > mid)
    modify(k << 1 | 1, l, r, x, y);
  else
    modify(k << 1, l, mid, x, y), modify(k << 1 | 1, mid + 1, r, x, y);
  pushup(k);
}
int query_mul(int k, int l, int r) {
  if (l <= s[k].l && s[k].r <= r) return s[k].mul;
  pushdown(k);
  int mid = (s[k].l + s[k].r) >> 1;
  if (r <= mid)
    return query_mul(k << 1, l, r);
  else if (l > mid)
    return query_mul(k << 1 | 1, l, r);
  else
    return 1ll * query_mul(k << 1, l, mid) * query_mul(k << 1 | 1, mid + 1, r) %
           MOD;
}
long long query_msk(int k, int l, int r) {
  if (l <= s[k].l && s[k].r <= r) return s[k].msk;
  pushdown(k);
  int mid = (s[k].l + s[k].r) >> 1;
  if (r <= mid)
    return query_msk(k << 1, l, r);
  else if (l > mid)
    return query_msk(k << 1 | 1, l, r);
  else
    return query_msk(k << 1, l, mid) | query_msk(k << 1 | 1, mid + 1, r);
}
int main() {
  scanf("%d%d", &n, &qu);
  sieve(MAXV);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, 1, n);
  while (qu--) {
    static char opt[10];
    scanf("%s", opt + 1);
    if (opt[1] == 'M') {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      long long msk = 0;
      for (int i = 1; i <= prcnt; i++)
        if (x % pr[i] == 0) msk |= 1ll << (i - 1);
      modify(1, l, r, x, msk);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      int mul1 = 1, mul2 = 1, mul = query_mul(1, l, r);
      long long msk = query_msk(1, l, r);
      for (int i = 1; i <= prcnt; i++)
        if (msk >> (i - 1) & 1) {
          mul1 = 1ll * mul1 * (pr[i] - 1) % MOD;
          mul2 = 1ll * mul2 * pr[i] % MOD;
        }
      mul = 1ll * mul * mul1 % MOD * qpow(mul2, MOD - 2) % MOD;
      printf("%d\n", mul);
    }
  }
  return 0;
}

### Prompt

Your challenge is to write a cpp solution to the following problem:

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;
template <typename T1, typename T2>
void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T neg = 1;
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= neg;
}
const int MAXV = 300;
const int MAXN = 4e5;
const int MOD = 1e9 + 7;
int qpow(int x, int e) {
  int ret = 1;
  for (; e; e >>= 1, x = 1ll * x * x % MOD)
    if (e & 1) ret = 1ll * ret * x % MOD;
  return ret;
}
bitset<MAXV + 5> vis;
int pr[MAXV / 3 + 5], prcnt = 0, phi[MAXV + 5];
void sieve(int n) {
  phi[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pr[++prcnt] = i;
    for (int j = 1; pr[j] * i <= n && j <= prcnt; j++) {
      vis[pr[j] * i] = 1;
      if (i % pr[j] == 0) break;
    }
  }
}
int n, qu, a[MAXN + 5];
struct node {
  int l, r, mul, lz;
  long long msk, tag_msk;
} s[MAXN * 4 + 5];
void pushup(int k) {
  s[k].mul = 1ll * s[k << 1].mul * s[k << 1 | 1].mul % MOD;
  s[k].msk = s[k << 1].msk | s[k << 1 | 1].msk;
}
void build(int k, int l, int r) {
  s[k].l = l;
  s[k].r = r;
  s[k].lz = 1;
  if (l == r) {
    s[k].mul = a[l];
    for (int i = 1; i <= prcnt; i++)
      if (a[l] % pr[i] == 0) s[k].msk |= 1ll << (i - 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  pushup(k);
}
void pushdown(int k) {
  if (s[k].lz != 1) {
    s[k << 1].mul = 1ll * s[k << 1].mul *
                    qpow(s[k].lz, s[k << 1].r - s[k << 1].l + 1) % MOD;
    s[k << 1].lz = 1ll * s[k << 1].lz * s[k].lz % MOD;
    s[k << 1].msk = s[k << 1].msk | s[k].tag_msk;
    s[k << 1].tag_msk = s[k << 1].tag_msk | s[k].tag_msk;
    s[k << 1 | 1].mul = 1ll * s[k << 1 | 1].mul *
                        qpow(s[k].lz, s[k << 1 | 1].r - s[k << 1 | 1].l + 1) %
                        MOD;
    s[k << 1 | 1].lz = 1ll * s[k << 1 | 1].lz * s[k].lz % MOD;
    s[k << 1 | 1].msk = s[k << 1 | 1].msk | s[k].tag_msk;
    s[k << 1 | 1].tag_msk = s[k << 1 | 1].tag_msk | s[k].tag_msk;
    s[k].lz = 1;
    s[k].tag_msk = 0;
  }
}
void modify(int k, int l, int r, int x, long long y) {
  if (l <= s[k].l && s[k].r <= r) {
    s[k].mul = 1ll * s[k].mul * qpow(x, s[k].r - s[k].l + 1) % MOD;
    s[k].msk |= y;
    s[k].lz = 1ll * s[k].lz * x % MOD;
    s[k].tag_msk |= y;
    return;
  }
  pushdown(k);
  int mid = (s[k].l + s[k].r) >> 1;
  if (r <= mid)
    modify(k << 1, l, r, x, y);
  else if (l > mid)
    modify(k << 1 | 1, l, r, x, y);
  else
    modify(k << 1, l, mid, x, y), modify(k << 1 | 1, mid + 1, r, x, y);
  pushup(k);
}
int query_mul(int k, int l, int r) {
  if (l <= s[k].l && s[k].r <= r) return s[k].mul;
  pushdown(k);
  int mid = (s[k].l + s[k].r) >> 1;
  if (r <= mid)
    return query_mul(k << 1, l, r);
  else if (l > mid)
    return query_mul(k << 1 | 1, l, r);
  else
    return 1ll * query_mul(k << 1, l, mid) * query_mul(k << 1 | 1, mid + 1, r) %
           MOD;
}
long long query_msk(int k, int l, int r) {
  if (l <= s[k].l && s[k].r <= r) return s[k].msk;
  pushdown(k);
  int mid = (s[k].l + s[k].r) >> 1;
  if (r <= mid)
    return query_msk(k << 1, l, r);
  else if (l > mid)
    return query_msk(k << 1 | 1, l, r);
  else
    return query_msk(k << 1, l, mid) | query_msk(k << 1 | 1, mid + 1, r);
}
int main() {
  scanf("%d%d", &n, &qu);
  sieve(MAXV);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, 1, n);
  while (qu--) {
    static char opt[10];
    scanf("%s", opt + 1);
    if (opt[1] == 'M') {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      long long msk = 0;
      for (int i = 1; i <= prcnt; i++)
        if (x % pr[i] == 0) msk |= 1ll << (i - 1);
      modify(1, l, r, x, msk);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      int mul1 = 1, mul2 = 1, mul = query_mul(1, l, r);
      long long msk = query_msk(1, l, r);
      for (int i = 1; i <= prcnt; i++)
        if (msk >> (i - 1) & 1) {
          mul1 = 1ll * mul1 * (pr[i] - 1) % MOD;
          mul2 = 1ll * mul2 * pr[i] % MOD;
        }
      mul = 1ll * mul * mul1 % MOD * qpow(mul2, MOD - 2) % MOD;
      printf("%d\n", mul);
    }
  }
  return 0;
}

```