#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (T e : v) {
    os << e << ' ';
  }
  return os;
}
constexpr ll mod = 1e9 + 7;
constexpr int kMaxS = 2e6;
int s;
ll primes[kMaxS];
ll prods[kMaxS];
bool lazy[kMaxS];
ll primeupdate[kMaxS];
ll produpdate[kMaxS];
ll prime[301];
vector<ll> pf, calculated;
ll powmod(ll a, ll b) {
  if (b == 0) {
    return 1LL;
  }
  if (b % 2 == 0) {
    ll tmp = powmod(a, b / 2);
    return tmp * tmp % mod;
  }
  return a * powmod(a, b - 1) % mod;
}
void update(int idx, int L, int R) {
  if (!lazy[idx]) {
    return;
  }
  primes[idx] |= primeupdate[idx];
  prods[idx] = prods[idx] * powmod(produpdate[idx], R - L + 1) % mod;
  int l = 2 * idx, r = l + 1;
  if (r < 2 * s) {
    lazy[l] = lazy[r] = true;
    produpdate[l] = produpdate[l] * produpdate[idx] % mod;
    produpdate[r] = produpdate[r] * produpdate[idx] % mod;
    primeupdate[l] |= primeupdate[idx];
    primeupdate[r] |= primeupdate[idx];
  }
  lazy[idx] = false;
  produpdate[idx] = 1;
  primeupdate[idx] = 0;
}
void update(int l, int r, int x, int idx, int L, int R) {
  if (l == L && r == R) {
    lazy[idx] = true;
    produpdate[idx] = produpdate[idx] * x % mod;
    primeupdate[idx] |= prime[x];
    return;
  }
  prods[idx] = prods[idx] * powmod(x, r - l + 1) % mod;
  primes[idx] |= prime[x];
  int M = (L + R) / 2;
  if (r <= M) {
    update(l, r, x, 2 * idx, L, M);
  } else if (l > M) {
    update(l, r, x, 2 * idx + 1, M + 1, R);
  } else {
    update(l, M, x, 2 * idx, L, M);
    update(M + 1, r, x, 2 * idx + 1, M + 1, R);
  }
}
pair<ll, ll> get(int l, int r, int idx, int L, int R) {
  update(idx, L, R);
  if (l == L && r == R) {
    return {prods[idx], primes[idx]};
  }
  int M = (L + R) / 2;
  if (r <= M) {
    return get(l, r, 2 * idx, L, M);
  } else if (l > M) {
    return get(l, r, 2 * idx + 1, M + 1, R);
  } else {
    auto left = get(l, M, 2 * idx, L, M);
    auto right = get(M + 1, r, 2 * idx + 1, M + 1, R);
    return {left.first * right.first % mod, left.second | right.second};
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  {
    auto is_prime = [](int num) {
      if (num % 2 == 0) {
        return num == 2;
      }
      for (int j = 3; j * j <= num; j += 2) {
        if (num % j == 0) {
          return false;
        }
      }
      return true;
    };
    for (int i = 2; i <= 300; ++i) {
      if (is_prime(i)) {
        pf.emplace_back(i);
      }
    }
    for (int i = 2; i <= 300; ++i) {
      ll cur = 0;
      for (int j = 0; j < pf.size() && pf[j] <= i; ++j) {
        if (i % pf[j] == 0) {
          cur |= 1LL << j;
        }
      }
      prime[i] = cur;
    }
    calculated.resize(pf.size());
    for (int i = 0; i < pf.size(); ++i) {
      ll inv = powmod(pf[i], mod - 2);
      calculated[i] = (pf[i] - 1LL) * inv % mod;
    }
  }
  int n, q;
  cin >> n >> q;
  s = 1;
  while (s < n) {
    s *= 2;
  }
  auto print_arr = [&] {
    cout << "Prods\n";
    for (int i = 0; i < n; ++i) {
      (void)get(i + 1, i + 1, 1, 1, s);
      cout << dec << prods[s + i] << ' ';
    }
    cout << '\n';
  };
  function<void(int, int, int)> print_prods = [&](int idx, int l, int r) {
    update(idx, l, r);
    cout << dec << "(" << l << "," << r << "): " << prods[idx] << '\n';
    if (idx < s) {
      int m = (l + r) / 2;
      print_prods(2 * idx, l, m);
      print_prods(2 * idx + 1, m + 1, r);
    }
  };
  assert(2 * s < 2e6);
  for (int i = 0; i < 2 * s; ++i) {
    prods[i] = 1;
    produpdate[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    prods[s + i] = a;
    primes[s + i] = prime[a];
  }
  for (int j = s - 1; j > 0; --j) {
    int l = 2 * j, r = l + 1;
    prods[j] = prods[l] * prods[r] % mod;
    primes[j] = primes[l] | primes[r];
  }
  while (q--) {
    string cmd;
    cin >> cmd;
    int l, r;
    cin >> l >> r;
    if (cmd == "MULTIPLY") {
      int x;
      cin >> x;
      update(l, r, x, 1, 1, s);
    } else if (cmd == "TOTIENT") {
      auto tmp = get(l, r, 1, 1, s);
      ll prod = tmp.first, p = tmp.second;
      int i = 0;
      while (p) {
        if (p & 1) {
          prod = prod * calculated[i] % mod;
        }
        ++i;
        p /= 2;
      }
      cout << prod << '\n';
    } else {
      cerr << "Invalid command\n";
      exit(1);
    }
  }
  return 0;
}
