#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define Gondozu ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector <pair<int, int>>;
using vvi = vector <vector<int>>;
const int OO = 1e9 + 5;
const int N = 2e5 + 5;
const ll IDN = 0, LAZY_IDN = 0;
struct SegTree {
vector <ll> tree;
vector <ll> lazy;
static int n;
ll combine(ll a, ll b) {
return max(a, b);
}
void build(int inputN) {
n = inputN;
if (__builtin_popcount(n) != 1)
n = 1 << (__lg(n) + 1);
tree.resize(n << 1, IDN);
lazy.resize(n << 1, LAZY_IDN);
}
void propagate(int k, int sl, int sr) {
if (lazy[k] != LAZY_IDN) {
tree[k] += lazy[k];
if (sl != sr) {
lazy[k << 1] += lazy[k];
lazy[k << 1 | 1] += lazy[k];
}
}
lazy[k] = LAZY_IDN;
}
void update(int ql, int qr, ll v, int k = 1, int sl = 0, int sr = n - 1) {
propagate(k, sl, sr);
if (qr < sl || sr < ql || ql > qr) return;
if (ql <= sl && qr >= sr) {
lazy[k] += v;
propagate(k, sl, sr);
return;
}
int mid = (sl + sr) / 2;
update(ql, qr, v, k << 1, sl, mid);
update(ql, qr, v, (k << 1) | 1, mid + 1, sr);
tree[k] = combine(tree[k << 1], tree[k << 1 | 1]);
}
ll query(int ql, int qr, int k = 1, int sl = 0, int sr = n - 1) {
propagate(k, sl, sr);
if (qr < sl || sr < ql || ql > qr) return IDN;
if (ql <= sl && qr >= sr) return tree[k];
int mid = (sl + sr) / 2;
ll left = query(ql, qr, k << 1, sl, mid);
ll right = query(ql, qr, k << 1 | 1, mid + 1, sr);
return combine(left, right);
}
};
int SegTree::n = 0;
void TC()
{
int n, q;
cin >> n >> q;
SegTree two, three, five, seven;
two.build(n);
three.build(n);
five.build(n);
seven.build(n);
while (q--){
string t;
int l,r,v;
cin >> t >> l >> r;
--l, --r;
if(t == "MULTIPLY"){
cin >> v;
int cnt = 0;
while (v % 2 == 0)
cnt++, v/=2;
two.update(l,r,cnt);
cnt = 0;
while (v % 3 == 0)
cnt++, v/=3;
three.update(l,r,cnt);
cnt = 0;
while (v % 5 == 0)
cnt++, v/=5;
five.update(l,r,cnt);
cnt = 0;
while (v % 7 == 0)
cnt++, v/=7;
seven.update(l,r,cnt);
} else {
cout << "ANSWER " << max({
two.query(l,r),
three.query(l,r),
five.query(l,r),
seven.query(l,r)
}) << '\n';
}
}
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#endif
Gondozu
int t = 1;
// cin >> t;
while (t--) {
TC();
cout << '\n';
}
return 0;
}