#include <bits/stdc++.h>
const int XN = 4e5 + 11, PC = 62, P = 1e9 + 7,
          prime[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,
                     37,  41,  43,  47,  53,  59,  61,  67,  71,  73,  79,
                     83,  89,  97,  101, 103, 107, 109, 113, 127, 131, 137,
                     139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
                     197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257,
                     263, 269, 271, 277, 281, 283, 293};
int pinv[PC];
int Add(int x, int const &y) { return (x += y) >= P ? x - P : x; }
int Minus(int x, int const &y) { return (x -= y) < 0 ? x + P : x; }
int Mul(long long x, int const &y) { return x * y % P; }
int Pow(long long base, int v) {
  long long res;
  for (res = 1; v; v >>= 1, (base *= base) %= P)
    if (v & 1) (res *= base) %= P;
  return res;
}
std::bitset<PC> Divide(int x) {
  std::bitset<PC> res{0};
  for (int i = 0; x != 1; ++i)
    if (x % prime[i] == 0) {
      res[i] = 1;
      do x /= prime[i];
      while (x % prime[i] == 0);
    }
  return res;
}
std::pair<std::bitset<PC>, int> Merge(
    std::pair<std::bitset<PC>, int> const &a,
    std::pair<std::bitset<PC>, int> const &b) {
  return {a.first | b.first, (long long)a.second * b.second % P};
}
struct SegTree {
  struct Node {
    Node *son[2];
    std::pair<std::bitset<PC>, int> sum, tag;
    Node(std::pair<std::bitset<PC>, int> const &sum) : sum(sum), tag{{0}, 1} {}
    void Modify(std::pair<std::bitset<PC>, int> d, int len) {
      tag = Merge(tag, d);
      sum.first |= d.first;
      sum.second = Mul(sum.second, Pow(d.second, len));
    }
    void Down(int L, int R) {
      if (tag.second != 1) {
        int M = (L + R) / 2;
        son[0]->Modify(tag, M - L + 1);
        son[1]->Modify(tag, R - M);
        tag = {{0}, 1};
      }
    }
    void Up() { sum = Merge(son[0]->sum, son[1]->sum); }
  } * root;
  int L, R;
  SegTree(int a[], int n) : L(1), R(n) {
    std::function<void(Node *&, int, int)> Build = [&](Node *&pos, int L,
                                                       int R) {
      if (L == R) {
        pos = new Node({Divide(a[L]), a[L]});
      } else {
        pos = new Node({{0}, 0});
        int M = (L + R) / 2;
        Build(pos->son[0], L, M);
        Build(pos->son[1], M + 1, R);
        pos->Up();
      }
    };
    Build(root, 1, n);
  }
  void Modify(int l, int r, int x) {
    std::pair<std::bitset<PC>, int> d = {Divide(x), x};
    std::function<void(Node *, int, int)> Modify = [&](Node *pos, int L,
                                                       int R) {
      if (l <= L && R <= r) {
        pos->Modify(d, R - L + 1);
      } else {
        int M = (L + R) / 2;
        pos->Down(L, R);
        if (l <= M) Modify(pos->son[0], L, M);
        if (M + 1 <= r) Modify(pos->son[1], M + 1, R);
        pos->Up();
      }
    };
    Modify(root, L, R);
  }
  int Query(int l, int r) {
    std::function<std::pair<std::bitset<PC>, int>(Node *, int, int)> Query =
        [&](Node *pos, int L, int R) -> std::pair<std::bitset<PC>, int> {
      if (l <= L && R <= r)
        return pos->sum;
      else {
        int M = (L + R) / 2;
        pos->Down(L, R);
        std::pair<std::bitset<PC>, int> res{{0}, 1};
        if (l <= M) res = Merge(res, Query(pos->son[0], L, M));
        if (M + 1 <= r) res = Merge(res, Query(pos->son[1], M + 1, R));
        return res;
      }
    };
    auto res = Query(root, L, R);
    int Ans = res.second;
    for (int i = 0; i < PC; ++i)
      if (res.first[i]) Ans = Mul(Ans, Mul(prime[i] - 1, pinv[i]));
    return Ans;
  }
};
int main() {
  for (int i = 0; i < PC; ++i) pinv[i] = Pow(prime[i], P - 2);
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int n, q;
  std::cin >> n >> q;
  static int a[XN];
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  SegTree seg(a, n);
  for (int i = 1; i <= q; ++i) {
    std::string op;
    std::cin >> op;
    int l, r, x;
    std::cin >> l >> r;
    if (op[0] == 'M') {
      std::cin >> x;
      seg.Modify(l, r, x);
    } else {
      std::cout << seg.Query(l, r) << '\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>
const int XN = 4e5 + 11, PC = 62, P = 1e9 + 7,
          prime[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,
                     37,  41,  43,  47,  53,  59,  61,  67,  71,  73,  79,
                     83,  89,  97,  101, 103, 107, 109, 113, 127, 131, 137,
                     139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
                     197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257,
                     263, 269, 271, 277, 281, 283, 293};
int pinv[PC];
int Add(int x, int const &y) { return (x += y) >= P ? x - P : x; }
int Minus(int x, int const &y) { return (x -= y) < 0 ? x + P : x; }
int Mul(long long x, int const &y) { return x * y % P; }
int Pow(long long base, int v) {
  long long res;
  for (res = 1; v; v >>= 1, (base *= base) %= P)
    if (v & 1) (res *= base) %= P;
  return res;
}
std::bitset<PC> Divide(int x) {
  std::bitset<PC> res{0};
  for (int i = 0; x != 1; ++i)
    if (x % prime[i] == 0) {
      res[i] = 1;
      do x /= prime[i];
      while (x % prime[i] == 0);
    }
  return res;
}
std::pair<std::bitset<PC>, int> Merge(
    std::pair<std::bitset<PC>, int> const &a,
    std::pair<std::bitset<PC>, int> const &b) {
  return {a.first | b.first, (long long)a.second * b.second % P};
}
struct SegTree {
  struct Node {
    Node *son[2];
    std::pair<std::bitset<PC>, int> sum, tag;
    Node(std::pair<std::bitset<PC>, int> const &sum) : sum(sum), tag{{0}, 1} {}
    void Modify(std::pair<std::bitset<PC>, int> d, int len) {
      tag = Merge(tag, d);
      sum.first |= d.first;
      sum.second = Mul(sum.second, Pow(d.second, len));
    }
    void Down(int L, int R) {
      if (tag.second != 1) {
        int M = (L + R) / 2;
        son[0]->Modify(tag, M - L + 1);
        son[1]->Modify(tag, R - M);
        tag = {{0}, 1};
      }
    }
    void Up() { sum = Merge(son[0]->sum, son[1]->sum); }
  } * root;
  int L, R;
  SegTree(int a[], int n) : L(1), R(n) {
    std::function<void(Node *&, int, int)> Build = [&](Node *&pos, int L,
                                                       int R) {
      if (L == R) {
        pos = new Node({Divide(a[L]), a[L]});
      } else {
        pos = new Node({{0}, 0});
        int M = (L + R) / 2;
        Build(pos->son[0], L, M);
        Build(pos->son[1], M + 1, R);
        pos->Up();
      }
    };
    Build(root, 1, n);
  }
  void Modify(int l, int r, int x) {
    std::pair<std::bitset<PC>, int> d = {Divide(x), x};
    std::function<void(Node *, int, int)> Modify = [&](Node *pos, int L,
                                                       int R) {
      if (l <= L && R <= r) {
        pos->Modify(d, R - L + 1);
      } else {
        int M = (L + R) / 2;
        pos->Down(L, R);
        if (l <= M) Modify(pos->son[0], L, M);
        if (M + 1 <= r) Modify(pos->son[1], M + 1, R);
        pos->Up();
      }
    };
    Modify(root, L, R);
  }
  int Query(int l, int r) {
    std::function<std::pair<std::bitset<PC>, int>(Node *, int, int)> Query =
        [&](Node *pos, int L, int R) -> std::pair<std::bitset<PC>, int> {
      if (l <= L && R <= r)
        return pos->sum;
      else {
        int M = (L + R) / 2;
        pos->Down(L, R);
        std::pair<std::bitset<PC>, int> res{{0}, 1};
        if (l <= M) res = Merge(res, Query(pos->son[0], L, M));
        if (M + 1 <= r) res = Merge(res, Query(pos->son[1], M + 1, R));
        return res;
      }
    };
    auto res = Query(root, L, R);
    int Ans = res.second;
    for (int i = 0; i < PC; ++i)
      if (res.first[i]) Ans = Mul(Ans, Mul(prime[i] - 1, pinv[i]));
    return Ans;
  }
};
int main() {
  for (int i = 0; i < PC; ++i) pinv[i] = Pow(prime[i], P - 2);
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int n, q;
  std::cin >> n >> q;
  static int a[XN];
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  SegTree seg(a, n);
  for (int i = 1; i <= q; ++i) {
    std::string op;
    std::cin >> op;
    int l, r, x;
    std::cin >> l >> r;
    if (op[0] == 'M') {
      std::cin >> x;
      seg.Modify(l, r, x);
    } else {
      std::cout << seg.Query(l, r) << '\n';
    }
  }
  return 0;
}

```