#include <bits/stdc++.h>
using namespace std;
class fenwickTree {
 public:
  int n;
  vector<long long> treeFirst;
  vector<long long> treeSecond;
  fenwickTree(int n) {
    this->n = n;
    treeFirst = vector<long long>(n + 1, 0);
    treeSecond = vector<long long>(n + 1, 0);
  }
  void reset() {
    fill(begin(treeFirst), end(treeFirst), 0);
    fill(begin(treeSecond), end(treeSecond), 0);
  }
  void update(vector<long long>& tree, int idx, long long val) {
    while (idx <= n) {
      tree[idx] += val;
      idx += idx & -idx;
    }
  }
  void update(int l, int r, long long val) {
    update(treeFirst, l, val);
    update(treeSecond, l, val * (l - 1));
    if (r + 1 <= n) {
      update(treeFirst, r + 1, -val);
      update(treeSecond, r + 1, -val * r);
    }
  }
  long long query(vector<long long>& tree, int r) {
    long long res = 0;
    while (r > 0) {
      res += tree[r];
      r -= r & -r;
    }
    return res;
  }
  long long query(int r) {
    return query(treeFirst, r) * r - query(treeSecond, r);
  }
  long long query(int l, int r) { return query(r) - query(l - 1); }
};
const int MAX_PRIME = 300;
const int MAX_X = 302;
const long long mod = 1000000007LL;
const int MAX_MEM = 200010;
long long memo[MAX_MEM];
int useMemo = 0;
long long modPow(long long a, long long p) {
  if (p < MAX_MEM && memo[p] != -1 && useMemo) {
    return memo[p];
  }
  if (p == 0) {
    return 1;
  }
  long long res = modPow(a, p / 2);
  res = (res * res) % mod;
  if (p % 2) {
    res = (a * res) % mod;
  }
  if (p < MAX_MEM && useMemo) {
    memo[p] = res;
  }
  return res;
}
long long modInverse(long long a) { return modPow(a, mod - 2); }
bool isPrime[MAX_PRIME];
vector<int> primes;
vector<long long> primeInv;
int factors[MAX_X][MAX_PRIME];
char operation[20];
void calcPrimes() {
  fill(begin(isPrime), end(isPrime), true);
  for (int i = 2; i < MAX_PRIME; ++i) {
    if (isPrime[i]) {
      primes.push_back(i);
      for (int j = i + i; j < MAX_PRIME; j += i) {
        isPrime[j] = false;
      }
    }
  }
}
void calcFactors() {
  for (int i = 1; i < MAX_X; ++i) {
    int tmp = i;
    for (int j = 0; j < primes.size(); ++j) {
      int cnt = 0;
      while (tmp % primes[j] == 0) {
        tmp /= primes[j];
        cnt++;
      }
      factors[i][j] = cnt;
    }
  }
}
const int MAX_N = 400040;
class query {
 public:
  char op;
  int l, r;
  int x;
  query(char op, int l, int r, int x = -1) {
    this->op = op;
    this->l = l;
    this->r = r;
    this->x = x;
  }
};
int a[MAX_N];
long long ans[MAX_N];
vector<query> queries;
vector<int> queryOf[MAX_PRIME];
int main() {
  ios::sync_with_stdio(false);
  calcPrimes();
  calcFactors();
  for (int i = 0; i < primes.size(); ++i) {
    primeInv.push_back(modInverse(primes[i]));
  }
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[i] = x;
  }
  for (int qIdx = 0; qIdx < q; ++qIdx) {
    cin >> operation;
    if (operation[0] == 'T') {
      int l, r;
      cin >> l >> r;
      queries.push_back(query('T', l, r));
      for (int pr = 0; pr < primes.size(); ++pr) {
        queryOf[pr].push_back(qIdx);
      }
    } else {
      int l, r, x;
      cin >> l >> r >> x;
      queries.push_back(query('M', l, r, x));
      for (int pr = 0; pr < primes.size(); ++pr) {
        if (factors[x][pr] > 0) {
          queryOf[pr].push_back(qIdx);
        }
      }
    }
    ans[qIdx] = 1;
  }
  fenwickTree tree(n);
  useMemo = 1;
  for (int pr = 0; pr < primes.size(); ++pr) {
    tree.reset();
    for (int i = 0; i < n; ++i) {
      tree.update(i + 1, i + 1, factors[a[i]][pr]);
    }
    fill(begin(memo), end(memo), -1);
    for (int qIdx : queryOf[pr]) {
      auto query = queries[qIdx];
      if (query.op == 'T') {
        long long cnt = tree.query(query.l, query.r);
        if (cnt > 0) {
          ans[qIdx] = (ans[qIdx] * modPow(primes[pr], cnt)) % mod;
          long long totient = (1LL - primeInv[pr] + mod) % mod;
          ans[qIdx] = (ans[qIdx] * totient) % mod;
        }
      } else {
        tree.update(query.l, query.r, factors[query.x][pr]);
      }
    }
  }
  for (int i = 0; i < q; ++i) {
    if (queries[i].op == 'T') {
      cout << ans[i] << "\n";
    }
  }
  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;
class fenwickTree {
 public:
  int n;
  vector<long long> treeFirst;
  vector<long long> treeSecond;
  fenwickTree(int n) {
    this->n = n;
    treeFirst = vector<long long>(n + 1, 0);
    treeSecond = vector<long long>(n + 1, 0);
  }
  void reset() {
    fill(begin(treeFirst), end(treeFirst), 0);
    fill(begin(treeSecond), end(treeSecond), 0);
  }
  void update(vector<long long>& tree, int idx, long long val) {
    while (idx <= n) {
      tree[idx] += val;
      idx += idx & -idx;
    }
  }
  void update(int l, int r, long long val) {
    update(treeFirst, l, val);
    update(treeSecond, l, val * (l - 1));
    if (r + 1 <= n) {
      update(treeFirst, r + 1, -val);
      update(treeSecond, r + 1, -val * r);
    }
  }
  long long query(vector<long long>& tree, int r) {
    long long res = 0;
    while (r > 0) {
      res += tree[r];
      r -= r & -r;
    }
    return res;
  }
  long long query(int r) {
    return query(treeFirst, r) * r - query(treeSecond, r);
  }
  long long query(int l, int r) { return query(r) - query(l - 1); }
};
const int MAX_PRIME = 300;
const int MAX_X = 302;
const long long mod = 1000000007LL;
const int MAX_MEM = 200010;
long long memo[MAX_MEM];
int useMemo = 0;
long long modPow(long long a, long long p) {
  if (p < MAX_MEM && memo[p] != -1 && useMemo) {
    return memo[p];
  }
  if (p == 0) {
    return 1;
  }
  long long res = modPow(a, p / 2);
  res = (res * res) % mod;
  if (p % 2) {
    res = (a * res) % mod;
  }
  if (p < MAX_MEM && useMemo) {
    memo[p] = res;
  }
  return res;
}
long long modInverse(long long a) { return modPow(a, mod - 2); }
bool isPrime[MAX_PRIME];
vector<int> primes;
vector<long long> primeInv;
int factors[MAX_X][MAX_PRIME];
char operation[20];
void calcPrimes() {
  fill(begin(isPrime), end(isPrime), true);
  for (int i = 2; i < MAX_PRIME; ++i) {
    if (isPrime[i]) {
      primes.push_back(i);
      for (int j = i + i; j < MAX_PRIME; j += i) {
        isPrime[j] = false;
      }
    }
  }
}
void calcFactors() {
  for (int i = 1; i < MAX_X; ++i) {
    int tmp = i;
    for (int j = 0; j < primes.size(); ++j) {
      int cnt = 0;
      while (tmp % primes[j] == 0) {
        tmp /= primes[j];
        cnt++;
      }
      factors[i][j] = cnt;
    }
  }
}
const int MAX_N = 400040;
class query {
 public:
  char op;
  int l, r;
  int x;
  query(char op, int l, int r, int x = -1) {
    this->op = op;
    this->l = l;
    this->r = r;
    this->x = x;
  }
};
int a[MAX_N];
long long ans[MAX_N];
vector<query> queries;
vector<int> queryOf[MAX_PRIME];
int main() {
  ios::sync_with_stdio(false);
  calcPrimes();
  calcFactors();
  for (int i = 0; i < primes.size(); ++i) {
    primeInv.push_back(modInverse(primes[i]));
  }
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[i] = x;
  }
  for (int qIdx = 0; qIdx < q; ++qIdx) {
    cin >> operation;
    if (operation[0] == 'T') {
      int l, r;
      cin >> l >> r;
      queries.push_back(query('T', l, r));
      for (int pr = 0; pr < primes.size(); ++pr) {
        queryOf[pr].push_back(qIdx);
      }
    } else {
      int l, r, x;
      cin >> l >> r >> x;
      queries.push_back(query('M', l, r, x));
      for (int pr = 0; pr < primes.size(); ++pr) {
        if (factors[x][pr] > 0) {
          queryOf[pr].push_back(qIdx);
        }
      }
    }
    ans[qIdx] = 1;
  }
  fenwickTree tree(n);
  useMemo = 1;
  for (int pr = 0; pr < primes.size(); ++pr) {
    tree.reset();
    for (int i = 0; i < n; ++i) {
      tree.update(i + 1, i + 1, factors[a[i]][pr]);
    }
    fill(begin(memo), end(memo), -1);
    for (int qIdx : queryOf[pr]) {
      auto query = queries[qIdx];
      if (query.op == 'T') {
        long long cnt = tree.query(query.l, query.r);
        if (cnt > 0) {
          ans[qIdx] = (ans[qIdx] * modPow(primes[pr], cnt)) % mod;
          long long totient = (1LL - primeInv[pr] + mod) % mod;
          ans[qIdx] = (ans[qIdx] * totient) % mod;
        }
      } else {
        tree.update(query.l, query.r, factors[query.x][pr]);
      }
    }
  }
  for (int i = 0; i < q; ++i) {
    if (queries[i].op == 'T') {
      cout << ans[i] << "\n";
    }
  }
  return 0;
}

```