#include <bits/stdc++.h>
using namespace std;
int p[305];
bool np[305];
struct qnode {
  int opt, l, r, x;
} q[400000 + 5];
int a[400000 + 5];
long long inv[305];
long long qp(long long a, int k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    k >>= 1;
  }
  return res;
}
struct SEGTREEmul {
  long long s[400000 * 4 + 5], mark[400000 * 4 + 5];
  void pu(int i) { s[i] = s[i * 2] * s[i * 2 + 1] % 1000000007; }
  void pd(int i, int l, int r) {
    if (mark[i] != 1) {
      mark[i * 2] = mark[i * 2] * mark[i] % 1000000007;
      mark[i * 2 + 1] = mark[i * 2 + 1] * mark[i] % 1000000007;
      int mid = (l + r) >> 1;
      s[i * 2] = s[i * 2] * qp(mark[i], mid - l + 1) % 1000000007;
      s[i * 2 + 1] = s[i * 2 + 1] * qp(mark[i], r - mid) % 1000000007;
      mark[i] = 1;
    }
  }
  void build(int i, int l, int r) {
    mark[i] = 1;
    if (l == r)
      s[i] = a[l];
    else {
      int mid = (l + r) >> 1;
      build(i * 2, l, mid);
      build(i * 2 + 1, mid + 1, r);
      pu(i);
    }
  }
  void add(int i, int l, int r, int ql, int qr, int x) {
    if (ql <= l && r <= qr) {
      s[i] = s[i] * qp(x, r - l + 1) % 1000000007;
      mark[i] = mark[i] * x % 1000000007;
      return;
    }
    if (qr < l || r < ql) return;
    pd(i, l, r);
    int mid = (l + r) >> 1;
    add(i * 2, l, mid, ql, qr, x);
    add(i * 2 + 1, mid + 1, r, ql, qr, x);
    pu(i);
  }
  long long ask(int i, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return s[i];
    if (qr < l || r < ql) return 1;
    pd(i, l, r);
    int mid = (l + r) >> 1;
    return ask(i * 2, l, mid, ql, qr) * ask(i * 2 + 1, mid + 1, r, ql, qr) %
           1000000007;
  }
} tmul;
struct SEGTREEflag {
  bool s[400000 * 4 + 5], mark[400000 * 4 + 5];
  void pu(int i) { s[i] = s[i * 2] || s[i * 2 + 1]; }
  void pd(int i) {
    if (mark[i]) {
      mark[i * 2] = mark[i * 2 + 1] = 1;
      s[i * 2] = s[i * 2 + 1] = 1;
      mark[i] = 0;
    }
  }
  void build(int i, int l, int r, int pr) {
    mark[i] = 0;
    if (l == r)
      s[i] = a[l] % pr == 0;
    else {
      int mid = (l + r) >> 1;
      build(i * 2, l, mid, pr);
      build(i * 2 + 1, mid + 1, r, pr);
      pu(i);
    }
  }
  void set(int i, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) {
      s[i] = 1;
      mark[i] = 1;
      return;
    }
    if (qr < l || r < ql) return;
    pd(i);
    int mid = (l + r) >> 1;
    set(i * 2, l, mid, ql, qr);
    set(i * 2 + 1, mid + 1, r, ql, qr);
    pu(i);
  }
  bool ask(int i, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return s[i];
    if (qr < l || r < ql) return 0;
    pd(i);
    int mid = (l + r) >> 1;
    return ask(i * 2, l, mid, ql, qr) || ask(i * 2 + 1, mid + 1, r, ql, qr);
  }
} tf;
long long ans[400000 + 5];
int main() {
  int num = 0;
  for (int i = 2; i <= 300; i++)
    if (np[i] == 0) {
      p[++num] = i;
      for (int j = i * 2; j <= 300; j += i) np[j] = 1;
    }
  inv[1] = 1;
  for (int i = 2; i <= 300; i++)
    inv[i] = inv[1000000007 % i] * (1000000007 - 1000000007 / i) % 1000000007;
  int n, Q;
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= Q; i++) {
    char s[15];
    scanf("%s%d%d", s, &q[i].l, &q[i].r);
    if (s[0] == 'T')
      q[i].opt = 2;
    else {
      q[i].opt = 1;
      scanf("%d", &q[i].x);
    }
  }
  tmul.build(1, 1, n);
  for (int i = 1; i <= Q; i++) ans[i] = 1;
  for (int i = 1; i <= Q; i++) {
    if (q[i].opt == 1)
      tmul.add(1, 1, n, q[i].l, q[i].r, q[i].x);
    else
      ans[i] = ans[i] * tmul.ask(1, 1, n, q[i].l, q[i].r);
  }
  for (int r = 1; r <= num; r++) {
    int pr = p[r];
    tf.build(1, 1, n, pr);
    for (int i = 1; i <= Q; i++) {
      if (q[i].opt == 1) {
        if (q[i].x % pr == 0) tf.set(1, 1, n, q[i].l, q[i].r);
      } else {
        if (tf.ask(1, 1, n, q[i].l, q[i].r))
          ans[i] = ans[i] * (1 - inv[pr] + 1000000007) % 1000000007;
      }
    }
  }
  for (int i = 1; i <= Q; i++)
    if (q[i].opt == 2) printf("%I64d\n", ans[i]);
  return 0;
}

### Prompt

Please provide a CPP coded solution 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;
int p[305];
bool np[305];
struct qnode {
  int opt, l, r, x;
} q[400000 + 5];
int a[400000 + 5];
long long inv[305];
long long qp(long long a, int k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    k >>= 1;
  }
  return res;
}
struct SEGTREEmul {
  long long s[400000 * 4 + 5], mark[400000 * 4 + 5];
  void pu(int i) { s[i] = s[i * 2] * s[i * 2 + 1] % 1000000007; }
  void pd(int i, int l, int r) {
    if (mark[i] != 1) {
      mark[i * 2] = mark[i * 2] * mark[i] % 1000000007;
      mark[i * 2 + 1] = mark[i * 2 + 1] * mark[i] % 1000000007;
      int mid = (l + r) >> 1;
      s[i * 2] = s[i * 2] * qp(mark[i], mid - l + 1) % 1000000007;
      s[i * 2 + 1] = s[i * 2 + 1] * qp(mark[i], r - mid) % 1000000007;
      mark[i] = 1;
    }
  }
  void build(int i, int l, int r) {
    mark[i] = 1;
    if (l == r)
      s[i] = a[l];
    else {
      int mid = (l + r) >> 1;
      build(i * 2, l, mid);
      build(i * 2 + 1, mid + 1, r);
      pu(i);
    }
  }
  void add(int i, int l, int r, int ql, int qr, int x) {
    if (ql <= l && r <= qr) {
      s[i] = s[i] * qp(x, r - l + 1) % 1000000007;
      mark[i] = mark[i] * x % 1000000007;
      return;
    }
    if (qr < l || r < ql) return;
    pd(i, l, r);
    int mid = (l + r) >> 1;
    add(i * 2, l, mid, ql, qr, x);
    add(i * 2 + 1, mid + 1, r, ql, qr, x);
    pu(i);
  }
  long long ask(int i, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return s[i];
    if (qr < l || r < ql) return 1;
    pd(i, l, r);
    int mid = (l + r) >> 1;
    return ask(i * 2, l, mid, ql, qr) * ask(i * 2 + 1, mid + 1, r, ql, qr) %
           1000000007;
  }
} tmul;
struct SEGTREEflag {
  bool s[400000 * 4 + 5], mark[400000 * 4 + 5];
  void pu(int i) { s[i] = s[i * 2] || s[i * 2 + 1]; }
  void pd(int i) {
    if (mark[i]) {
      mark[i * 2] = mark[i * 2 + 1] = 1;
      s[i * 2] = s[i * 2 + 1] = 1;
      mark[i] = 0;
    }
  }
  void build(int i, int l, int r, int pr) {
    mark[i] = 0;
    if (l == r)
      s[i] = a[l] % pr == 0;
    else {
      int mid = (l + r) >> 1;
      build(i * 2, l, mid, pr);
      build(i * 2 + 1, mid + 1, r, pr);
      pu(i);
    }
  }
  void set(int i, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) {
      s[i] = 1;
      mark[i] = 1;
      return;
    }
    if (qr < l || r < ql) return;
    pd(i);
    int mid = (l + r) >> 1;
    set(i * 2, l, mid, ql, qr);
    set(i * 2 + 1, mid + 1, r, ql, qr);
    pu(i);
  }
  bool ask(int i, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return s[i];
    if (qr < l || r < ql) return 0;
    pd(i);
    int mid = (l + r) >> 1;
    return ask(i * 2, l, mid, ql, qr) || ask(i * 2 + 1, mid + 1, r, ql, qr);
  }
} tf;
long long ans[400000 + 5];
int main() {
  int num = 0;
  for (int i = 2; i <= 300; i++)
    if (np[i] == 0) {
      p[++num] = i;
      for (int j = i * 2; j <= 300; j += i) np[j] = 1;
    }
  inv[1] = 1;
  for (int i = 2; i <= 300; i++)
    inv[i] = inv[1000000007 % i] * (1000000007 - 1000000007 / i) % 1000000007;
  int n, Q;
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= Q; i++) {
    char s[15];
    scanf("%s%d%d", s, &q[i].l, &q[i].r);
    if (s[0] == 'T')
      q[i].opt = 2;
    else {
      q[i].opt = 1;
      scanf("%d", &q[i].x);
    }
  }
  tmul.build(1, 1, n);
  for (int i = 1; i <= Q; i++) ans[i] = 1;
  for (int i = 1; i <= Q; i++) {
    if (q[i].opt == 1)
      tmul.add(1, 1, n, q[i].l, q[i].r, q[i].x);
    else
      ans[i] = ans[i] * tmul.ask(1, 1, n, q[i].l, q[i].r);
  }
  for (int r = 1; r <= num; r++) {
    int pr = p[r];
    tf.build(1, 1, n, pr);
    for (int i = 1; i <= Q; i++) {
      if (q[i].opt == 1) {
        if (q[i].x % pr == 0) tf.set(1, 1, n, q[i].l, q[i].r);
      } else {
        if (tf.ask(1, 1, n, q[i].l, q[i].r))
          ans[i] = ans[i] * (1 - inv[pr] + 1000000007) % 1000000007;
      }
    }
  }
  for (int i = 1; i <= Q; i++)
    if (q[i].opt == 2) printf("%I64d\n", ans[i]);
  return 0;
}

```