#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
bool p[305];
int pr[305];
int cnt = 0;
struct seg {
  bitset<62> tg, tag;
  int tm, ttm;
  int l, r;
} node[400005 * 4];
int n, q;
int a[400005];
bitset<62> gbt(int x) {
  bitset<62> ans;
  for (int i = 1; i <= cnt && pr[i] <= x; i++) {
    if (x % pr[i] == 0) ans[i - 1] = 1;
  }
  return ans;
}
int fb[305];
int fpow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (1LL * ans * a) % mod;
    a = (1LL * a * a) % mod;
    b >>= 1;
  }
  return ans;
}
int grb(bitset<62> x) {
  int ans = 1;
  for (int i = 0; i < 62; i++) {
    if (x[i]) {
      ans = (1LL * ans * fb[pr[i + 1]]) % mod;
      ans = (1LL * ans * (pr[i + 1] - 1)) % mod;
    }
  }
  return ans;
}
void pd(int u) {
  if (node[u].ttm > 1) {
    if (node[u].l != node[u].r) {
      node[u << 1].ttm = (1LL * node[u << 1].ttm * node[u].ttm) % mod;
      node[u << 1 | 1].ttm = (1LL * node[u << 1 | 1].ttm * node[u].ttm) % mod;
    }
    node[u].tm =
        (1LL * node[u].tm * fpow(node[u].ttm, node[u].r - node[u].l + 1)) % mod;
    node[u].ttm = 1;
  }
  if (node[u].l != node[u].r) {
    node[u << 1].tag |= node[u].tag;
    node[u << 1 | 1].tag |= node[u].tag;
  }
  node[u].tg |= node[u].tag;
  node[u].tag = 0;
  return;
}
void rec(int u) {
  node[u].tg = node[u << 1].tg | node[u << 1 | 1].tg;
  node[u].tm = (1LL * node[u << 1].tm * node[u << 1 | 1].tm) % mod;
  return;
}
void build(int u, int l, int r) {
  node[u].l = l, node[u].r = r;
  node[u].ttm = 1;
  if (l == r) {
    node[u].tg = gbt(a[l]);
    node[u].tm = a[l];
    return;
  }
  build(u << 1, l, (l + r >> 1));
  build(u << 1 | 1, (l + r >> 1) + 1, r);
  rec(u);
  return;
}
void modify(int u, int l, int r, int v, bitset<62> b) {
  if (node[u].l == l && node[u].r == r) {
    node[u].ttm = (1LL * node[u].ttm * v) % mod;
    node[u].tag |= b;
    pd(u);
    return;
  }
  pd(u);
  if (r <= node[u << 1].r) {
    modify(u << 1, l, r, v, b);
    pd(u << 1 | 1);
  } else if (l >= node[u << 1 | 1].l) {
    modify(u << 1 | 1, l, r, v, b);
    pd(u << 1);
  } else {
    modify(u << 1, l, node[u << 1].r, v, b);
    modify(u << 1 | 1, node[u << 1 | 1].l, r, v, b);
  }
  rec(u);
  return;
}
int queryt(int u, int l, int r) {
  pd(u);
  if (node[u].l == l && node[u].r == r) {
    return node[u].tm;
  }
  if (r <= node[u << 1].r)
    return queryt(u << 1, l, r);
  else if (l >= node[u << 1 | 1].l)
    return queryt(u << 1 | 1, l, r);
  else
    return (1LL * queryt(u << 1, l, node[u << 1].r) *
            queryt(u << 1 | 1, node[u << 1 | 1].l, r)) %
           mod;
}
bitset<62> queryb(int u, int l, int r) {
  pd(u);
  if (node[u].l == l && node[u].r == r) {
    return node[u].tg;
  }
  if (r <= node[u << 1].r)
    return queryb(u << 1, l, r);
  else if (l >= node[u << 1 | 1].l)
    return queryb(u << 1 | 1, l, r);
  else
    return queryb(u << 1, l, node[u << 1].r) |
           queryb(u << 1 | 1, node[u << 1 | 1].l, r);
}
int main() {
  for (int i = 2; i <= 300; i++) {
    if (!p[i]) {
      for (int j = i * 2; j <= 300; j += i) p[j] = 1;
      pr[++cnt] = i;
    }
  }
  for (int i = 1; i <= 300; i++) fb[i] = fpow(i, mod - 2);
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  build(1, 1, n);
  while (q--) {
    char s[15];
    int l, r, x;
    scanf("%s", s + 1);
    if (s[1] == 'M') {
      scanf("%d%d%d", &l, &r, &x);
      modify(1, l, r, x, gbt(x));
    } else {
      scanf("%d%d", &l, &r);
      int x = queryt(1, l, r);
      bitset<62> gx = queryb(1, l, r);
      x = (1LL * x * grb(gx)) % mod;
      printf("%d\n", x);
    }
  }
  return 0;
}

### Prompt

Please formulate 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;
const int mod = 1e9 + 7;
bool p[305];
int pr[305];
int cnt = 0;
struct seg {
  bitset<62> tg, tag;
  int tm, ttm;
  int l, r;
} node[400005 * 4];
int n, q;
int a[400005];
bitset<62> gbt(int x) {
  bitset<62> ans;
  for (int i = 1; i <= cnt && pr[i] <= x; i++) {
    if (x % pr[i] == 0) ans[i - 1] = 1;
  }
  return ans;
}
int fb[305];
int fpow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (1LL * ans * a) % mod;
    a = (1LL * a * a) % mod;
    b >>= 1;
  }
  return ans;
}
int grb(bitset<62> x) {
  int ans = 1;
  for (int i = 0; i < 62; i++) {
    if (x[i]) {
      ans = (1LL * ans * fb[pr[i + 1]]) % mod;
      ans = (1LL * ans * (pr[i + 1] - 1)) % mod;
    }
  }
  return ans;
}
void pd(int u) {
  if (node[u].ttm > 1) {
    if (node[u].l != node[u].r) {
      node[u << 1].ttm = (1LL * node[u << 1].ttm * node[u].ttm) % mod;
      node[u << 1 | 1].ttm = (1LL * node[u << 1 | 1].ttm * node[u].ttm) % mod;
    }
    node[u].tm =
        (1LL * node[u].tm * fpow(node[u].ttm, node[u].r - node[u].l + 1)) % mod;
    node[u].ttm = 1;
  }
  if (node[u].l != node[u].r) {
    node[u << 1].tag |= node[u].tag;
    node[u << 1 | 1].tag |= node[u].tag;
  }
  node[u].tg |= node[u].tag;
  node[u].tag = 0;
  return;
}
void rec(int u) {
  node[u].tg = node[u << 1].tg | node[u << 1 | 1].tg;
  node[u].tm = (1LL * node[u << 1].tm * node[u << 1 | 1].tm) % mod;
  return;
}
void build(int u, int l, int r) {
  node[u].l = l, node[u].r = r;
  node[u].ttm = 1;
  if (l == r) {
    node[u].tg = gbt(a[l]);
    node[u].tm = a[l];
    return;
  }
  build(u << 1, l, (l + r >> 1));
  build(u << 1 | 1, (l + r >> 1) + 1, r);
  rec(u);
  return;
}
void modify(int u, int l, int r, int v, bitset<62> b) {
  if (node[u].l == l && node[u].r == r) {
    node[u].ttm = (1LL * node[u].ttm * v) % mod;
    node[u].tag |= b;
    pd(u);
    return;
  }
  pd(u);
  if (r <= node[u << 1].r) {
    modify(u << 1, l, r, v, b);
    pd(u << 1 | 1);
  } else if (l >= node[u << 1 | 1].l) {
    modify(u << 1 | 1, l, r, v, b);
    pd(u << 1);
  } else {
    modify(u << 1, l, node[u << 1].r, v, b);
    modify(u << 1 | 1, node[u << 1 | 1].l, r, v, b);
  }
  rec(u);
  return;
}
int queryt(int u, int l, int r) {
  pd(u);
  if (node[u].l == l && node[u].r == r) {
    return node[u].tm;
  }
  if (r <= node[u << 1].r)
    return queryt(u << 1, l, r);
  else if (l >= node[u << 1 | 1].l)
    return queryt(u << 1 | 1, l, r);
  else
    return (1LL * queryt(u << 1, l, node[u << 1].r) *
            queryt(u << 1 | 1, node[u << 1 | 1].l, r)) %
           mod;
}
bitset<62> queryb(int u, int l, int r) {
  pd(u);
  if (node[u].l == l && node[u].r == r) {
    return node[u].tg;
  }
  if (r <= node[u << 1].r)
    return queryb(u << 1, l, r);
  else if (l >= node[u << 1 | 1].l)
    return queryb(u << 1 | 1, l, r);
  else
    return queryb(u << 1, l, node[u << 1].r) |
           queryb(u << 1 | 1, node[u << 1 | 1].l, r);
}
int main() {
  for (int i = 2; i <= 300; i++) {
    if (!p[i]) {
      for (int j = i * 2; j <= 300; j += i) p[j] = 1;
      pr[++cnt] = i;
    }
  }
  for (int i = 1; i <= 300; i++) fb[i] = fpow(i, mod - 2);
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  build(1, 1, n);
  while (q--) {
    char s[15];
    int l, r, x;
    scanf("%s", s + 1);
    if (s[1] == 'M') {
      scanf("%d%d%d", &l, &r, &x);
      modify(1, l, r, x, gbt(x));
    } else {
      scanf("%d%d", &l, &r);
      int x = queryt(1, l, r);
      bitset<62> gx = queryb(1, l, r);
      x = (1LL * x * grb(gx)) % mod;
      printf("%d\n", x);
    }
  }
  return 0;
}

```