#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define N 400001
vector<int>primes;
int pos[301];
vector<int>v[301];
struct node
{
ll mask=0;
ll p=1;
}t[4*N+1],lazy[4*N+1];
int a[N+1];
ll pwr(ll a,ll b)
{
ll k=1;
while(b)
{
if(b&1)
k*=a;
a*=a;
k%=MOD;
a%=MOD;
b/=2;
}
return k;
}
void sieve()
{
for(int i=2;i<=300;++i)
{
if(!v[i].empty())
continue;
pos[i]=primes.size();
primes.push_back(i);
for(int j=i;j<=300;j+=i)
v[j].push_back(i);
}
}
void init(int nd,int s,int e)
{
lazy[nd].p=1;
lazy[nd].mask=0;
if(s==e)
{
t[nd].p=a[s];
for(int i=0;i<v[a[s]].size();++i)
t[nd].mask|=(1 <<pos[v[a[s]][i]]);
}
else
{
int m=s+(e-s)/2;
init(2*nd,s,m);
init(2*nd+1,m+1,e);
t[nd].mask=(t[2*nd].mask|t[2*nd+1].mask);
t[nd].p=(t[2*nd].p*t[2*nd+1].p)%MOD;
}
}
void upd(ll nd,ll s,ll e,ll l,ll r,ll val)
{
if(lazy[nd].p!=1)
{
t[nd].p=(t[nd].p*pwr(lazy[nd].p,e-s+1))%MOD;
t[nd].mask=(t[nd].mask|lazy[nd].mask);
if(s!=e)
{
lazy[2*nd].p=(lazy[2*nd].p*lazy[nd].p)%MOD;
lazy[2*nd+1].p=(lazy[2*nd+1].p*lazy[nd].p)%MOD;
lazy[2*nd].mask=(lazy[2*nd].mask|lazy[nd].mask);
lazy[2*nd+1].mask=(lazy[2*nd+1].mask|lazy[nd].mask);
}
lazy[nd].mask=0;
lazy[nd].p=1;
}
if(s>r||e<l||s>e)
return ;
if(s>=l&&e<=r)
{
t[nd].p=(t[nd].p*pwr(val,e-s+1))%MOD;
for(int i=0;i<v[val].size();++i)
{
t[nd].mask|=(1<<(pos[v[val][i]]));
if(s!=e)
{
lazy[2*nd].mask|=(1 <<(pos[v[val][i]]));
lazy[2*nd+1].mask|=(1 <<(pos[v[val][i]]));
}
}
if(s!=e)
{
lazy[2*nd].p=(lazy[2*nd].p*val)%MOD;
lazy[2*nd+1].p=(lazy[2*nd+1].p*val)%MOD;
}
return;
}
int m=s+(e-s)/2;
upd(2*nd,s,m,l,r,val);
upd(2*nd+1,m+1,e,l,r,val);
t[nd].mask=t[2*nd].mask|t[2*nd+1].mask;
t[nd].p=(t[2*nd].p*t[2*nd+1].p)%MOD;
}
pair<ll,ll> q(int nd,int s,int e,int l,int r)
{
if(lazy[nd].p!=1)
{
t[nd].p=(t[nd].p*pwr(lazy[nd].p,e-s+1))%MOD;
t[nd].mask=(t[nd].mask|lazy[nd].mask);
if(s!=e)
{
lazy[2*nd].p=(lazy[2*nd].p*lazy[nd].p)%MOD;
lazy[2*nd+1].p=(lazy[2*nd+1].p*lazy[nd].p)%MOD;
lazy[2*nd].mask=(lazy[2*nd].mask|lazy[nd].mask);
lazy[2*nd+1].mask=(lazy[2*nd+1].mask|lazy[nd].mask);
}
lazy[nd].mask=0;
lazy[nd].p=1;
}
if(s>r||e<l||s>e)
return {1,0};
if(s>=l&&e<=r)
{
return {t[nd].p,t[nd].mask};
}
int m=s+(e-s)/2;
pair<ll,ll>p1,p2,p;
p1=q(2*nd,s,m,l,r);
p2=q(2*nd+1,m+1,e,l,r);
p.first=(p1.first*p2.first)%MOD;
p.second=(p2.second|p1.second);
return p;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
sieve();
int n,m,i,j,k;
cin>>n>>m;
for(i=1;i<=n;++i)
cin>>a[i];
init(1,1,n);
while(m--)
{
string str;
cin>>str;
if(str[0]=='M')
{
int l,r,val;
cin>>l>>r>>val;
upd(1,1,n,l,r,val);
}
else
{
ll l,r;
cin>>l>>r;
pair<ll,ll>p=q(1,1,n,l,r);
ll msk=p.second;
ll ans=p.first;
ll pro=1;
ll prod=1;
while(msk)
{
int posn=(int)log2(msk&-msk);
prod=(prod*(primes[posn]-1))%MOD;
pro=(pro*(primes[posn]))%MOD;
msk-=(1<<posn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