#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  char c;
  do {
    c = getchar();
  } while (!isdigit(c));
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (isdigit(c));
  return x;
}
int opt() {
  char c;
  do {
    c = getchar();
  } while (c != 'M' && c != 'T');
  return c == 'M';
}
const long long mod = (long long)(1e9) + 7LL;
const int N = 400000 + 10;
const int P = 62 + 3;
const int V = 300 + 10;
long long qpow(long long a, long long p) {
  if (p == 0) return (a % mod > 0);
  long long r = qpow(a, p >> 1);
  r = r * r % mod;
  return (p & 1) ? (r * a % mod) : r;
}
int prime[P], cnt;
long long ph[P];
bitset<P> has[V];
int isprime(int x) {
  if (x < 2) return 0;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
int n, q, a[N];
namespace Tmul {
long long mul[N << 2], tag[N << 2];
void build(int o, int l, int r) {
  tag[o] = 1;
  if (l == r) {
    mul[o] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build((o << 1), l, mid);
  build(((o << 1) | 1), mid + 1, r);
  mul[o] = mul[(o << 1)] * mul[((o << 1) | 1)] % mod;
}
int inter(int l, int r, int a, int b) {
  l = max(l, a);
  r = min(r, b);
  return max(r - l + 1, 0);
}
void update(int o, int L, int R, int l, int r, long long x) {
  if (L > r || R < l) return;
  mul[o] = mul[o] * qpow(x, inter(L, R, l, r)) % mod;
  if (l <= L && R <= r) {
    tag[o] = tag[o] * x % mod;
    return;
  }
  int mid = (L + R) >> 1;
  update((o << 1), L, mid, l, r, x);
  update(((o << 1) | 1), mid + 1, R, l, r, x);
}
long long query(int o, int L, int R, int l, int r, long long m = 1) {
  if (L > r || R < l) return 1;
  if (l <= L && R <= r) return mul[o] * qpow(m, R - L + 1) % mod;
  m = m * tag[o] % mod;
  int mid = (L + R) >> 1;
  return query((o << 1), L, mid, l, r, m) *
         query(((o << 1) | 1), mid + 1, R, l, r, m) % mod;
}
}  // namespace Tmul
namespace Tfac {
bitset<P> fs[N << 2], tag[N << 2];
inline void pushup(int o) { fs[o] = fs[(o << 1)] | fs[((o << 1) | 1)]; }
void pushdown(int o) {
  if (tag[o].any()) {
    fs[(o << 1)] |= tag[o];
    fs[((o << 1) | 1)] |= tag[o];
    tag[(o << 1)] |= tag[o];
    tag[((o << 1) | 1)] |= tag[o];
    tag[o].reset();
  }
  assert(!tag[o].any());
}
void build(int o, int l, int r) {
  tag[o].reset();
  if (l == r) {
    fs[o] = has[a[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build((o << 1), l, mid);
  build(((o << 1) | 1), mid + 1, r);
  pushup(o);
}
void update(int o, int L, int R, int l, int r, const bitset<P> &x) {
  if (L > r || R < l) return;
  if (l <= L && R <= r) {
    tag[o] |= x;
    fs[o] |= x;
    return;
  }
  pushdown(o);
  int mid = (L + R) >> 1;
  update((o << 1), L, mid, l, r, x);
  update(((o << 1) | 1), mid + 1, R, l, r, x);
  pushup(o);
}
bitset<P> query(int o, int L, int R, int l, int r) {
  if (L > r || R < l) return bitset<P>(0);
  if (l <= L && R <= r) return fs[o];
  pushdown(o);
  int mid = (L + R) >> 1;
  return query((o << 1), L, mid, l, r) |
         query(((o << 1) | 1), mid + 1, R, l, r);
}
}  // namespace Tfac
int main() {
  for (int i = 1; i <= 300; i++) {
    has[i] = bitset<P>(0);
    if (isprime(i)) {
      has[i][cnt] = 1;
      ph[cnt] = 1LL * (i - 1) * qpow(i, mod - 2) % mod;
      prime[cnt++] = i;
    } else
      for (int j = 0; j < cnt; j++) has[i][j] = (i % prime[j] == 0);
  }
  n = read();
  q = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  Tmul::build(1, 1, n);
  Tfac::build(1, 1, n);
  int l, r, x, o;
  long long ans = 0;
  while (q--) {
    o = opt();
    l = read();
    r = read();
    if (o) {
      x = read();
      if (x == 1) continue;
      Tmul::update(1, 1, n, l, r, x);
      Tfac::update(1, 1, n, l, r, has[x]);
    } else {
      ans = Tmul::query(1, 1, n, l, r);
      bitset<P> fs = Tfac::query(1, 1, n, l, r);
      for (int i = 0; i < cnt; i++)
        if (fs[i]) ans = ans * ph[i] % mod;
      printf("%d\n", (int)(ans));
    }
  }
  return 0;
}

### Prompt

Please create a solution in Cpp 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;
int read() {
  int x = 0;
  char c;
  do {
    c = getchar();
  } while (!isdigit(c));
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (isdigit(c));
  return x;
}
int opt() {
  char c;
  do {
    c = getchar();
  } while (c != 'M' && c != 'T');
  return c == 'M';
}
const long long mod = (long long)(1e9) + 7LL;
const int N = 400000 + 10;
const int P = 62 + 3;
const int V = 300 + 10;
long long qpow(long long a, long long p) {
  if (p == 0) return (a % mod > 0);
  long long r = qpow(a, p >> 1);
  r = r * r % mod;
  return (p & 1) ? (r * a % mod) : r;
}
int prime[P], cnt;
long long ph[P];
bitset<P> has[V];
int isprime(int x) {
  if (x < 2) return 0;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
int n, q, a[N];
namespace Tmul {
long long mul[N << 2], tag[N << 2];
void build(int o, int l, int r) {
  tag[o] = 1;
  if (l == r) {
    mul[o] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build((o << 1), l, mid);
  build(((o << 1) | 1), mid + 1, r);
  mul[o] = mul[(o << 1)] * mul[((o << 1) | 1)] % mod;
}
int inter(int l, int r, int a, int b) {
  l = max(l, a);
  r = min(r, b);
  return max(r - l + 1, 0);
}
void update(int o, int L, int R, int l, int r, long long x) {
  if (L > r || R < l) return;
  mul[o] = mul[o] * qpow(x, inter(L, R, l, r)) % mod;
  if (l <= L && R <= r) {
    tag[o] = tag[o] * x % mod;
    return;
  }
  int mid = (L + R) >> 1;
  update((o << 1), L, mid, l, r, x);
  update(((o << 1) | 1), mid + 1, R, l, r, x);
}
long long query(int o, int L, int R, int l, int r, long long m = 1) {
  if (L > r || R < l) return 1;
  if (l <= L && R <= r) return mul[o] * qpow(m, R - L + 1) % mod;
  m = m * tag[o] % mod;
  int mid = (L + R) >> 1;
  return query((o << 1), L, mid, l, r, m) *
         query(((o << 1) | 1), mid + 1, R, l, r, m) % mod;
}
}  // namespace Tmul
namespace Tfac {
bitset<P> fs[N << 2], tag[N << 2];
inline void pushup(int o) { fs[o] = fs[(o << 1)] | fs[((o << 1) | 1)]; }
void pushdown(int o) {
  if (tag[o].any()) {
    fs[(o << 1)] |= tag[o];
    fs[((o << 1) | 1)] |= tag[o];
    tag[(o << 1)] |= tag[o];
    tag[((o << 1) | 1)] |= tag[o];
    tag[o].reset();
  }
  assert(!tag[o].any());
}
void build(int o, int l, int r) {
  tag[o].reset();
  if (l == r) {
    fs[o] = has[a[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build((o << 1), l, mid);
  build(((o << 1) | 1), mid + 1, r);
  pushup(o);
}
void update(int o, int L, int R, int l, int r, const bitset<P> &x) {
  if (L > r || R < l) return;
  if (l <= L && R <= r) {
    tag[o] |= x;
    fs[o] |= x;
    return;
  }
  pushdown(o);
  int mid = (L + R) >> 1;
  update((o << 1), L, mid, l, r, x);
  update(((o << 1) | 1), mid + 1, R, l, r, x);
  pushup(o);
}
bitset<P> query(int o, int L, int R, int l, int r) {
  if (L > r || R < l) return bitset<P>(0);
  if (l <= L && R <= r) return fs[o];
  pushdown(o);
  int mid = (L + R) >> 1;
  return query((o << 1), L, mid, l, r) |
         query(((o << 1) | 1), mid + 1, R, l, r);
}
}  // namespace Tfac
int main() {
  for (int i = 1; i <= 300; i++) {
    has[i] = bitset<P>(0);
    if (isprime(i)) {
      has[i][cnt] = 1;
      ph[cnt] = 1LL * (i - 1) * qpow(i, mod - 2) % mod;
      prime[cnt++] = i;
    } else
      for (int j = 0; j < cnt; j++) has[i][j] = (i % prime[j] == 0);
  }
  n = read();
  q = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  Tmul::build(1, 1, n);
  Tfac::build(1, 1, n);
  int l, r, x, o;
  long long ans = 0;
  while (q--) {
    o = opt();
    l = read();
    r = read();
    if (o) {
      x = read();
      if (x == 1) continue;
      Tmul::update(1, 1, n, l, r, x);
      Tfac::update(1, 1, n, l, r, has[x]);
    } else {
      ans = Tmul::query(1, 1, n, l, r);
      bitset<P> fs = Tfac::query(1, 1, n, l, r);
      for (int i = 0; i < cnt; i++)
        if (fs[i]) ans = ans * ph[i] % mod;
      printf("%d\n", (int)(ans));
    }
  }
  return 0;
}

```