#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define EPS 0.00000001
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5+7;
const int N = 1e7+7;
int t[maxn << 2],in[maxn << 2],lazy[maxn << 2];
int prime[N];
void getprime()
{
for(int i=2;i<sqrt(1.0*N);i++)
if(!prime[i])
for(int j=i+i;j<N;j+=i)
prime[j] = 1;
prime[1] = 1;
prime[0] = 1;
}
void pushdown(int i,int b,int e)
{
if(lazy[i])
{
int mid = (b + e) / 2;
in[i << 1] = !prime[lazy[i]] * (mid - b + 1);
in[i << 1 | 1] = !prime[lazy[i]] * (e - mid);
t[i << 1] = lazy[i];
t[i << 1 | 1] = lazy[i];
lazy[i << 1] = lazy[i];
lazy[i << 1 | 1] = lazy[i];
lazy[i] = 0;
}
}
void add(int i,int b,int e,int pos,int val)
{
if(b == e)
{
in[i] -= !prime[t[i]];
t[i] += val;
in[i] += !prime[t[i]];
return ;
}
pushdown(i, b, e);
int mid = (b + e) / 2;
if(pos <= mid) add(i << 1, b, mid, pos, val);
else add(i << 1 | 1, mid + 1, e, pos, val);
in[i] = in[i << 1] + in[i << 1 | 1];
}
void replace(int i,int b,int e,int l,int r,int val)
{
if(b >= l && e <= r)
{
in[i] = (!prime[val]) * (e - b + 1);
t[i] = val;
lazy[i] = val;
return ;
}
pushdown(i, b, e);
int mid = (b + e) / 2;
if(r <= mid) replace(i << 1, b, mid, l, r, val);
else if(l > mid) replace(i<< 1 | 1, mid + 1, e, l, r, val);
else
{
replace(i << 1, b, mid, l, r, val);
replace(i << 1 | 1, mid + 1, e, l, r, val);
}
in[i] = in[i << 1] + in[i << 1 | 1];
}
int query(int i,int b,int e,int l,int r)
{
if(b >= l && e <= r)
return in[i];
pushdown(i, b, e);
int mid = (b + e) / 2;
if(r <= mid) return query(i << 1, b, mid, l, r);
else if(l > mid) return query(i << 1 | 1, mid + 1, e, l, r);
else return query(i << 1, b, mid, l, r) + query(i << 1 | 1, mid + 1, e, l, r);
}
int main()
{
getprime();
int T;
scanf("%d",&T);
while(T--)
{
char s[5];
int n,m,x,a,b,c;
scanf("%d%d",&n,&m);
memset(t,0,sizeof(t));
memset(in,0,sizeof(in));
memset(lazy,0,sizeof(lazy));
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
add(1,1,n,i,x);
}
for(int i=0;i<m;i++)
{
scanf("%s%d%d",s,&a,&b);
if(s[0] == 'A') add(1,1,n,b,a);
else if(s[0] == 'Q') printf("%d
", query(1,1,n,a,b));
else
{
scanf("%d",&c);
replace(1,1,n,b,c,a);
}
}
}
}