#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<ll, ll>;
inline void NYA() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll fpow(ll b, ll p, ll mod) {
  ll ans = 1, now = b;
  while (p) {
    if (p & 1) ans = ans * now % mod;
    p /= 2;
    now = now * now % mod;
  }
  return ans;
}
ll fpow(ll b, ll p) { return fpow(b, p, (ll)(1e9 + 7)); }
void minify(ll &a, const ll &b) {
  if (b < a) a = b;
}
void maxify(ll &a, const ll &b) {
  if (b > a) a = b;
}
bool isprime(ll n) {
  for (ll i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
struct SegTree {
  ull tag[1600060];
  ull ans[1600060];
  void build() {
    memset(tag, 0, sizeof(tag));
    memset(ans, 0, sizeof(ans));
  }
  void add(ll id, ll l, ll r, ll L, ll R, ull mask) {
    if (l > R || r < L) return;
    if (l >= L && r <= R) {
      tag[id] |= mask;
      ans[id] |= mask;
      return;
    }
    ll m = (l + r) / 2;
    add((id * 2 + 1), l, m, L, R, mask);
    add((id * 2 + 2), m + 1, r, L, R, mask);
    ans[id] = ans[(id * 2 + 1)] | ans[(id * 2 + 2)] | tag[id];
  }
  ull ask(ll id, ll l, ll r, ll L, ll R) {
    if (l > R || r < L) return (ull)0;
    if (l >= L && r <= R) return ans[id];
    ll m = (l + r) / 2;
    return ask((id * 2 + 1), l, m, L, R) | ask((id * 2 + 2), m + 1, r, L, R) |
           tag[id];
  }
} seg;
struct SegTree2 {
  struct Node {
    ll ans, siz, tag;
  } a[1600060];
  inline ll Ans(ll id) {
    return a[id].ans * fpow(a[id].tag, a[id].siz) % (ll)(1e9 + 7);
  }
  inline void push(ll id) {
    a[(id * 2 + 1)].tag = a[(id * 2 + 1)].tag * a[id].tag % (ll)(1e9 + 7);
    a[(id * 2 + 2)].tag = a[(id * 2 + 2)].tag * a[id].tag % (ll)(1e9 + 7);
    a[id].tag = 1;
  }
  inline void pull(ll id) {
    a[id].ans = Ans((id * 2 + 1)) * Ans((id * 2 + 2)) % (ll)(1e9 + 7);
  }
  void build(ll id, ll l, ll r) {
    a[id].ans = 1;
    a[id].siz = r - l + 1;
    a[id].tag = 1;
    if (l == r) return;
    ll m = (l + r) / 2;
    build((id * 2 + 1), l, m);
    build((id * 2 + 2), m + 1, r);
  }
  void mul(ll id, ll l, ll r, ll L, ll R, ll x) {
    if (l > R || r < L) return;
    if (l >= L && r <= R) {
      a[id].tag = a[id].tag * x % (ll)(1e9 + 7);
      return;
    }
    ll m = (l + r) / 2;
    push(id);
    mul((id * 2 + 1), l, m, L, R, x);
    mul((id * 2 + 2), m + 1, r, L, R, x);
    pull(id);
  }
  ll ask(ll id, ll l, ll r, ll L, ll R) {
    if (l > R || r < L) return 1;
    if (l >= L && r <= R) return Ans(id);
    ll m = (l + r) / 2;
    push(id);
    ll ans = ask((id * 2 + 1), l, m, L, R) * ask((id * 2 + 2), m + 1, r, L, R) %
             (ll)(1e9 + 7);
    pull(id);
    return ans;
  }
} pro;
int32_t main() {
  NYA();
  vector<ll> pr;
  vector<ll> inv;
  for (ll i = 2; i <= 300; i++)
    if (isprime(i)) {
      pr.emplace_back(i);
      inv.emplace_back(fpow(i, (ll)(1e9 + 7) - 2));
    }
  ll n, q;
  cin >> n >> q;
  seg.build();
  pro.build(0, 1, n);
  for (ll id = 1; id <= n; id++) {
    ll t;
    cin >> t;
    pro.mul(0, 1, n, id, id, t);
    for (ll i = 0; i <= 61; i++) {
      ll cnt = 0;
      while (t % pr[i] == 0) {
        cnt++;
        t /= pr[i];
      }
      if (cnt) seg.add(0, 1, n, id, id, (1ll << i));
    }
  }
  string op;
  while (q--) {
    cin >> op;
    if (op[0] == 'M') {
      ll l, r, t;
      cin >> l >> r >> t;
      pro.mul(0, 1, n, l, r, t);
      for (ll i = 0; i <= 61; i++) {
        ll cnt = 0;
        while (t % pr[i] == 0) {
          cnt++;
          t /= pr[i];
        }
        if (cnt) seg.add(0, 1, n, l, r, (1ll << i));
      }
    } else {
      ll l, r;
      cin >> l >> r;
      ull mask = seg.ask(0, 1, n, l, r);
      ll ans = pro.ask(0, 1, n, l, r);
      for (ll i = 0; i <= 61; i++)
        if (mask & (1ll << i)) {
          ans = ans * inv[i] % (ll)(1e9 + 7) * (pr[i] - 1) % (ll)(1e9 + 7);
        }
      cout << ans << "\n";
    }
  }
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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;
using ll = long long;
using ull = unsigned long long;
using pii = pair<ll, ll>;
inline void NYA() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll fpow(ll b, ll p, ll mod) {
  ll ans = 1, now = b;
  while (p) {
    if (p & 1) ans = ans * now % mod;
    p /= 2;
    now = now * now % mod;
  }
  return ans;
}
ll fpow(ll b, ll p) { return fpow(b, p, (ll)(1e9 + 7)); }
void minify(ll &a, const ll &b) {
  if (b < a) a = b;
}
void maxify(ll &a, const ll &b) {
  if (b > a) a = b;
}
bool isprime(ll n) {
  for (ll i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
struct SegTree {
  ull tag[1600060];
  ull ans[1600060];
  void build() {
    memset(tag, 0, sizeof(tag));
    memset(ans, 0, sizeof(ans));
  }
  void add(ll id, ll l, ll r, ll L, ll R, ull mask) {
    if (l > R || r < L) return;
    if (l >= L && r <= R) {
      tag[id] |= mask;
      ans[id] |= mask;
      return;
    }
    ll m = (l + r) / 2;
    add((id * 2 + 1), l, m, L, R, mask);
    add((id * 2 + 2), m + 1, r, L, R, mask);
    ans[id] = ans[(id * 2 + 1)] | ans[(id * 2 + 2)] | tag[id];
  }
  ull ask(ll id, ll l, ll r, ll L, ll R) {
    if (l > R || r < L) return (ull)0;
    if (l >= L && r <= R) return ans[id];
    ll m = (l + r) / 2;
    return ask((id * 2 + 1), l, m, L, R) | ask((id * 2 + 2), m + 1, r, L, R) |
           tag[id];
  }
} seg;
struct SegTree2 {
  struct Node {
    ll ans, siz, tag;
  } a[1600060];
  inline ll Ans(ll id) {
    return a[id].ans * fpow(a[id].tag, a[id].siz) % (ll)(1e9 + 7);
  }
  inline void push(ll id) {
    a[(id * 2 + 1)].tag = a[(id * 2 + 1)].tag * a[id].tag % (ll)(1e9 + 7);
    a[(id * 2 + 2)].tag = a[(id * 2 + 2)].tag * a[id].tag % (ll)(1e9 + 7);
    a[id].tag = 1;
  }
  inline void pull(ll id) {
    a[id].ans = Ans((id * 2 + 1)) * Ans((id * 2 + 2)) % (ll)(1e9 + 7);
  }
  void build(ll id, ll l, ll r) {
    a[id].ans = 1;
    a[id].siz = r - l + 1;
    a[id].tag = 1;
    if (l == r) return;
    ll m = (l + r) / 2;
    build((id * 2 + 1), l, m);
    build((id * 2 + 2), m + 1, r);
  }
  void mul(ll id, ll l, ll r, ll L, ll R, ll x) {
    if (l > R || r < L) return;
    if (l >= L && r <= R) {
      a[id].tag = a[id].tag * x % (ll)(1e9 + 7);
      return;
    }
    ll m = (l + r) / 2;
    push(id);
    mul((id * 2 + 1), l, m, L, R, x);
    mul((id * 2 + 2), m + 1, r, L, R, x);
    pull(id);
  }
  ll ask(ll id, ll l, ll r, ll L, ll R) {
    if (l > R || r < L) return 1;
    if (l >= L && r <= R) return Ans(id);
    ll m = (l + r) / 2;
    push(id);
    ll ans = ask((id * 2 + 1), l, m, L, R) * ask((id * 2 + 2), m + 1, r, L, R) %
             (ll)(1e9 + 7);
    pull(id);
    return ans;
  }
} pro;
int32_t main() {
  NYA();
  vector<ll> pr;
  vector<ll> inv;
  for (ll i = 2; i <= 300; i++)
    if (isprime(i)) {
      pr.emplace_back(i);
      inv.emplace_back(fpow(i, (ll)(1e9 + 7) - 2));
    }
  ll n, q;
  cin >> n >> q;
  seg.build();
  pro.build(0, 1, n);
  for (ll id = 1; id <= n; id++) {
    ll t;
    cin >> t;
    pro.mul(0, 1, n, id, id, t);
    for (ll i = 0; i <= 61; i++) {
      ll cnt = 0;
      while (t % pr[i] == 0) {
        cnt++;
        t /= pr[i];
      }
      if (cnt) seg.add(0, 1, n, id, id, (1ll << i));
    }
  }
  string op;
  while (q--) {
    cin >> op;
    if (op[0] == 'M') {
      ll l, r, t;
      cin >> l >> r >> t;
      pro.mul(0, 1, n, l, r, t);
      for (ll i = 0; i <= 61; i++) {
        ll cnt = 0;
        while (t % pr[i] == 0) {
          cnt++;
          t /= pr[i];
        }
        if (cnt) seg.add(0, 1, n, l, r, (1ll << i));
      }
    } else {
      ll l, r;
      cin >> l >> r;
      ull mask = seg.ask(0, 1, n, l, r);
      ll ans = pro.ask(0, 1, n, l, r);
      for (ll i = 0; i <= 61; i++)
        if (mask & (1ll << i)) {
          ans = ans * inv[i] % (ll)(1e9 + 7) * (pr[i] - 1) % (ll)(1e9 + 7);
        }
      cout << ans << "\n";
    }
  }
  return 0;
}

```