#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
const int mod = 1e9 + 7;
const int maxn = 305;
int n, q, a[N], comp[N], cnt = 0, ifact[maxn], pr[maxn];
char s[10];
bool check(int x) {
  if (x < 2) return false;
  if (x < 4) return true;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
int binPow(int x, int y) {
  int ans = 1;
  while (y > 0) {
    if (y & 1) ans = 1LL * ans * x % mod;
    x = 1LL * x * x % mod;
    y >>= 1;
  }
  return ans;
}
void prep() {
  ifact[0] = 1;
  for (int i = 1; i < maxn; i++) ifact[i] = binPow(i, mod - 2);
}
struct Node {
  int mul;
  bitset<65> pfactor;
  Node(int mul = 1, bitset<65> pfactor = {}) : mul(mul), pfactor(pfactor) {}
  Node operator+(const Node &rhs) const {
    return Node(1LL * mul * rhs.mul % mod, pfactor | rhs.pfactor);
  }
};
struct SegmentTree {
  Node node[N << 2];
  int lazy[N << 2];
  bitset<65> lz[N << 2];
  void dolazy(int i, int l, int r) {
    if (lazy[i]) {
      node[i].mul = 1LL * node[i].mul * binPow(lazy[i], r - l + 1) % mod;
      if (l != r) {
        lazy[i << 1] = 1LL * lazy[i << 1] * lazy[i] % mod;
        lazy[i << 1 | 1] = 1LL * lazy[i << 1 | 1] * lazy[i] % mod;
      }
      lazy[i] = 1;
    }
  }
  void dolz(int i, int l, int r) {
    if (lz[i].count() > 0) {
      node[i].pfactor |= lz[i];
      if (l != r) {
        lz[i << 1] |= lz[i];
        lz[i << 1 | 1] |= lz[i];
      }
      lz[i].reset();
    }
  }
  void init(int i, int l, int r) {
    if (l == r) {
      node[i].mul = a[l];
      node[i].pfactor.reset();
      lazy[i] = 1;
      lz[i].reset();
      for (int j = 1; j <= cnt; j++)
        if (a[l] % pr[j] == 0) node[i].pfactor.set(j);
      return;
    }
    int mid = l + r >> 1;
    init(i << 1, l, mid);
    init(i << 1 | 1, mid + 1, r);
    node[i] = node[i << 1] + node[i << 1 | 1];
    lazy[i] = 1;
    lz[i].reset();
  }
  void update(int i, int l, int r, int a, int b, int val, bitset<65> factors) {
    dolazy(i, l, r);
    dolz(i, l, r);
    if (l > r || a > r || b < l) return;
    if (a <= l && r <= b) {
      node[i].mul = 1LL * node[i].mul * binPow(val, r - l + 1) % mod;
      node[i].pfactor |= factors;
      if (l != r) {
        lazy[i << 1] = 1LL * lazy[i << 1] * val % mod;
        lazy[i << 1 | 1] = 1LL * lazy[i << 1 | 1] * val % mod;
        lz[i << 1] |= factors;
        lz[i << 1 | 1] |= factors;
      }
      return;
    }
    int mid = l + r >> 1;
    update(i << 1, l, mid, a, b, val, factors);
    update(i << 1 | 1, mid + 1, r, a, b, val, factors);
    node[i] = node[i << 1] + node[i << 1 | 1];
  }
  Node query(int i, int l, int r, int a, int b) {
    if (l > r || a > r || b < l) return Node();
    dolazy(i, l, r);
    dolz(i, l, r);
    if (a <= l && r <= b) return node[i];
    int mid = l + r >> 1;
    return query(i << 1, l, mid, a, b) + query(i << 1 | 1, mid + 1, r, a, b);
  }
} it;
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= 300; i++)
    if (check(i)) comp[i] = ++cnt, pr[cnt] = i;
  prep();
  it.init(1, 1, n);
  while (q--) {
    scanf("%s", s);
    if (s[0] == 'M') {
      int l, r, x;
      scanf("%d %d %d", &l, &r, &x);
      bitset<65> pfact;
      for (int i = 1; i <= cnt; i++)
        if (x % pr[i] == 0) pfact.set(i);
      it.update(1, 1, n, l, r, x, pfact);
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      Node ans = it.query(1, 1, n, l, r);
      int res = ans.mul;
      bitset<65> res2 = ans.pfactor;
      for (int i = 1; i <= cnt; i++)
        if (res2.test(i))
          res = 1LL * res * (pr[i] - 1) % mod * ifact[pr[i]] % mod;
      printf("%d\n", res);
    }
  }
  return 0;
}

### 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;
const int N = 4e5 + 5;
const int mod = 1e9 + 7;
const int maxn = 305;
int n, q, a[N], comp[N], cnt = 0, ifact[maxn], pr[maxn];
char s[10];
bool check(int x) {
  if (x < 2) return false;
  if (x < 4) return true;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
int binPow(int x, int y) {
  int ans = 1;
  while (y > 0) {
    if (y & 1) ans = 1LL * ans * x % mod;
    x = 1LL * x * x % mod;
    y >>= 1;
  }
  return ans;
}
void prep() {
  ifact[0] = 1;
  for (int i = 1; i < maxn; i++) ifact[i] = binPow(i, mod - 2);
}
struct Node {
  int mul;
  bitset<65> pfactor;
  Node(int mul = 1, bitset<65> pfactor = {}) : mul(mul), pfactor(pfactor) {}
  Node operator+(const Node &rhs) const {
    return Node(1LL * mul * rhs.mul % mod, pfactor | rhs.pfactor);
  }
};
struct SegmentTree {
  Node node[N << 2];
  int lazy[N << 2];
  bitset<65> lz[N << 2];
  void dolazy(int i, int l, int r) {
    if (lazy[i]) {
      node[i].mul = 1LL * node[i].mul * binPow(lazy[i], r - l + 1) % mod;
      if (l != r) {
        lazy[i << 1] = 1LL * lazy[i << 1] * lazy[i] % mod;
        lazy[i << 1 | 1] = 1LL * lazy[i << 1 | 1] * lazy[i] % mod;
      }
      lazy[i] = 1;
    }
  }
  void dolz(int i, int l, int r) {
    if (lz[i].count() > 0) {
      node[i].pfactor |= lz[i];
      if (l != r) {
        lz[i << 1] |= lz[i];
        lz[i << 1 | 1] |= lz[i];
      }
      lz[i].reset();
    }
  }
  void init(int i, int l, int r) {
    if (l == r) {
      node[i].mul = a[l];
      node[i].pfactor.reset();
      lazy[i] = 1;
      lz[i].reset();
      for (int j = 1; j <= cnt; j++)
        if (a[l] % pr[j] == 0) node[i].pfactor.set(j);
      return;
    }
    int mid = l + r >> 1;
    init(i << 1, l, mid);
    init(i << 1 | 1, mid + 1, r);
    node[i] = node[i << 1] + node[i << 1 | 1];
    lazy[i] = 1;
    lz[i].reset();
  }
  void update(int i, int l, int r, int a, int b, int val, bitset<65> factors) {
    dolazy(i, l, r);
    dolz(i, l, r);
    if (l > r || a > r || b < l) return;
    if (a <= l && r <= b) {
      node[i].mul = 1LL * node[i].mul * binPow(val, r - l + 1) % mod;
      node[i].pfactor |= factors;
      if (l != r) {
        lazy[i << 1] = 1LL * lazy[i << 1] * val % mod;
        lazy[i << 1 | 1] = 1LL * lazy[i << 1 | 1] * val % mod;
        lz[i << 1] |= factors;
        lz[i << 1 | 1] |= factors;
      }
      return;
    }
    int mid = l + r >> 1;
    update(i << 1, l, mid, a, b, val, factors);
    update(i << 1 | 1, mid + 1, r, a, b, val, factors);
    node[i] = node[i << 1] + node[i << 1 | 1];
  }
  Node query(int i, int l, int r, int a, int b) {
    if (l > r || a > r || b < l) return Node();
    dolazy(i, l, r);
    dolz(i, l, r);
    if (a <= l && r <= b) return node[i];
    int mid = l + r >> 1;
    return query(i << 1, l, mid, a, b) + query(i << 1 | 1, mid + 1, r, a, b);
  }
} it;
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= 300; i++)
    if (check(i)) comp[i] = ++cnt, pr[cnt] = i;
  prep();
  it.init(1, 1, n);
  while (q--) {
    scanf("%s", s);
    if (s[0] == 'M') {
      int l, r, x;
      scanf("%d %d %d", &l, &r, &x);
      bitset<65> pfact;
      for (int i = 1; i <= cnt; i++)
        if (x % pr[i] == 0) pfact.set(i);
      it.update(1, 1, n, l, r, x, pfact);
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      Node ans = it.query(1, 1, n, l, r);
      int res = ans.mul;
      bitset<65> res2 = ans.pfactor;
      for (int i = 1; i <= cnt; i++)
        if (res2.test(i))
          res = 1LL * res * (pr[i] - 1) % mod * ifact[pr[i]] % mod;
      printf("%d\n", res);
    }
  }
  return 0;
}

```