#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;
}
