#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int tree[1001000],lazy[1001000],a[100100];
bool mark[1000100];
void initialize(int node,int b,int e)
{
if(b==e)
{
if(mark[a[e]]==false)
{
tree[node]=1;
}
else
{
tree[node]=0;
}
}
else
{
initialize(2*node,b,(b+e)/2);
initialize(2*node+1,((b+e)/2)+1,e);
tree[node]=(tree[node*2]+tree[node*2+1]);
}
}
int query(int node,int b,int e,int i,int j)
{
if(lazy[node]!=0)
{
if(mark[lazy[node]]==false)
{
tree[node]=(e-b+1);
}
else
{
tree[node]=0;
}
if(b!=e)
{
lazy[2*node]=lazy[node];
lazy[node*2+1]=lazy[node];
}
lazy[node]=0;
}
if(b>j||e<i)
{
return -10;
}
else if(b>=i&&e<=j)
{
return tree[node];
}
else
{
int p1=query(node*2,b,(b+e)/2,i,j);
int p2=query(2*node+1,((b+e)/2)+1,e,i,j);
if(p1==-10)
{
return p2;
}
else if(p2==-10)
{
return p1;
}
else
{
return p1+p2;
}
}
}
void update(int node,int b,int e,int i,int j,int v)
{
if(lazy[node]!=0)
{
if(mark[lazy[node]]==false)
{
tree[node]=e-b+1;
}
else
{
tree[node]=0;
}
if(b!=e)
{
lazy[2*node]=lazy[node];
lazy[2*node+1]=lazy[node];
}
lazy[node]=0;
}
if(b>j||e<i)
{
return;
}
else if(b>=i&&e<=j)
{
if(mark[v]==false)
{
tree[node]=e-b+1;
}
else
{
tree[node]=0;
}
if(b!=e)
{
lazy[node*2]=v;
lazy[2*node+1]=v;
}
return;
}
else
{
update(node*2,b,(b+e)/2,i,j,v);
update(2*node+1,((b+e)/2)+1,e,i,j,v);
tree[node]=(tree[node*2]+tree[node*2+1]);
}
}
void sieve(int n)
{
for(int i=3;i<1010;i=i+2)
{
if(mark[i]==false)
{
for(int j=i;j*i<n;++j)
{
if(mark[j*i]==false)
{
mark[i*j]=true;
}
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
mark[0]=true;
mark[1]=true;
for(int i=4;i<1000100;i=i+2)
{
mark[i]=true;
}
sieve(1000100);
for(int i=1;i<=t;++i)
{
int n,q;
scanf("%d%d",&n,&q);
printf("Case %d:\n", i);
for(int i=0;i<n;++i)
{
scanf("%d",&a[i]);
}
initialize(1,0,n-1);
while(q>0)
{
q--;
int ch,x,y,v;
scanf("%d%d%d",&ch,&x,&y);
if(ch==0)
{
scanf("%d",&v);
update(1,0,n-1,x-1,y-1,v);
}
else
{
printf("%d\n",query(1,0,n-1,x-1,y-1));
}
}
}
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNtYXRoPgojaW5jbHVkZTxjc3RkaW8+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCB0cmVlWzEwMDEwMDBdLGxhenlbMTAwMTAwMF0sYVsxMDAxMDBdOwpib29sIG1hcmtbMTAwMDEwMF07CnZvaWQgaW5pdGlhbGl6ZShpbnQgbm9kZSxpbnQgYixpbnQgZSkKewogICAgaWYoYj09ZSkKICAgIHsKICAgICAgICBpZihtYXJrW2FbZV1dPT1mYWxzZSkKICAgICAgICB7CiAgICAgICAgICAgdHJlZVtub2RlXT0xOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICB0cmVlW25vZGVdPTA7CiAgICAgICAgfQoKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBpbml0aWFsaXplKDIqbm9kZSxiLChiK2UpLzIpOwogICAgICAgIGluaXRpYWxpemUoMipub2RlKzEsKChiK2UpLzIpKzEsZSk7CiAgICAgICAgdHJlZVtub2RlXT0odHJlZVtub2RlKjJdK3RyZWVbbm9kZSoyKzFdKTsKICAgIH0KfQppbnQgcXVlcnkoaW50IG5vZGUsaW50IGIsaW50IGUsaW50IGksaW50IGopCnsKICAgIGlmKGxhenlbbm9kZV0hPTApCiAgICB7CiAgICAgICAgaWYobWFya1tsYXp5W25vZGVdXT09ZmFsc2UpCiAgICAgICAgewogICAgICAgICAgICB0cmVlW25vZGVdPShlLWIrMSk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHRyZWVbbm9kZV09MDsKICAgICAgICB9CiAgICAgICAgaWYoYiE9ZSkKICAgICAgICB7CgoKICAgICAgICBsYXp5WzIqbm9kZV09bGF6eVtub2RlXTsKICAgICAgICBsYXp5W25vZGUqMisxXT1sYXp5W25vZGVdOwogICAgICAgIH0KICAgICAgICBsYXp5W25vZGVdPTA7CiAgICB9CiAgICBpZihiPmp8fGU8aSkKICAgIHsKICAgICAgICByZXR1cm4gLTEwOwogICAgfQogICAgZWxzZSBpZihiPj1pJiZlPD1qKQogICAgewogICAgICAgIHJldHVybiB0cmVlW25vZGVdOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIGludCBwMT1xdWVyeShub2RlKjIsYiwoYitlKS8yLGksaik7CiAgICAgICAgaW50IHAyPXF1ZXJ5KDIqbm9kZSsxLCgoYitlKS8yKSsxLGUsaSxqKTsKCiAgICAgICAgaWYocDE9PS0xMCkKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBwMjsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZihwMj09LTEwKQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIHAxOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gcDErcDI7CiAgICAgICAgfQoKICAgIH0KfQogdm9pZCB1cGRhdGUoaW50IG5vZGUsaW50IGIsaW50IGUsaW50IGksaW50IGosaW50IHYpCiB7CiAgICAgaWYobGF6eVtub2RlXSE9MCkKICAgICB7CiAgICAgICAgIGlmKG1hcmtbbGF6eVtub2RlXV09PWZhbHNlKQogICAgICAgICB7CiAgICAgICAgICAgICB0cmVlW25vZGVdPWUtYisxOwogICAgICAgICB9CiAgICAgICAgIGVsc2UKICAgICAgICAgewogICAgICAgICAgICAgdHJlZVtub2RlXT0wOwogICAgICAgICB9CiAgICAgICAgIGlmKGIhPWUpCiAgICAgICAgIHsKCgogICAgICAgICBsYXp5WzIqbm9kZV09bGF6eVtub2RlXTsKICAgICAgICAgbGF6eVsyKm5vZGUrMV09bGF6eVtub2RlXTsKCiAgICAgICAgIH0KICAgICAgICAgbGF6eVtub2RlXT0wOwogICAgIH0KICAgICBpZihiPmp8fGU8aSkKICAgICB7CiAgICAgICAgIHJldHVybjsKICAgICB9CiAgICAgZWxzZSBpZihiPj1pJiZlPD1qKQogICAgIHsKICAgICAgICAgaWYobWFya1t2XT09ZmFsc2UpCiAgICAgICAgIHsKICAgICAgICAgICAgIHRyZWVbbm9kZV09ZS1iKzE7CiAgICAgICAgIH0KICAgICAgICAgZWxzZQogICAgICAgICB7CiAgICAgICAgICAgICB0cmVlW25vZGVdPTA7CiAgICAgICAgIH0KICAgICAgICAgaWYoYiE9ZSkKICAgICAgICAgewoKCiAgICAgICAgICAgIGxhenlbbm9kZSoyXT12OwogICAgICAgICAgICBsYXp5WzIqbm9kZSsxXT12OwogICAgICAgICB9CiAgICAgICAgIHJldHVybjsKICAgICB9CiAgICAgZWxzZQogICAgIHsKICAgICAgICAgdXBkYXRlKG5vZGUqMixiLChiK2UpLzIsaSxqLHYpOwogICAgICAgICB1cGRhdGUoMipub2RlKzEsKChiK2UpLzIpKzEsZSxpLGosdik7CiAgICAgICAgIHRyZWVbbm9kZV09KHRyZWVbbm9kZSoyXSt0cmVlW25vZGUqMisxXSk7CiAgICAgfQogfQogdm9pZCBzaWV2ZShpbnQgbikKIHsKICAgICBmb3IoaW50IGk9MztpPDEwMTA7aT1pKzIpCiAgICAgewogICAgICAgICBpZihtYXJrW2ldPT1mYWxzZSkKICAgICAgICAgewogICAgICAgICAgICAgZm9yKGludCBqPWk7aippPG47KytqKQogICAgICAgICAgICAgewogICAgICAgICAgICAgICAgIGlmKG1hcmtbaippXT09ZmFsc2UpCiAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICBtYXJrW2kqal09dHJ1ZTsKCiAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgfQogICAgICAgICB9CiAgICAgfQogfQoKIGludCBtYWluKCkKIHsKICAgICBpbnQgdDsKCiAgICAgc2NhbmYoIiVkIiwmdCk7CiAgICAgbWFya1swXT10cnVlOwogICAgIG1hcmtbMV09dHJ1ZTsKICAgICBmb3IoaW50IGk9NDtpPDEwMDAxMDA7aT1pKzIpCiAgICAgewogICAgICAgICBtYXJrW2ldPXRydWU7CiAgICAgfQogICAgIHNpZXZlKDEwMDAxMDApOwogICAgIGZvcihpbnQgaT0xO2k8PXQ7KytpKQogICAgIHsKCgogICAgICAgICBpbnQgbixxOwoKICAgICAgICAgc2NhbmYoIiVkJWQiLCZuLCZxKTsKICAgICAgICAgcHJpbnRmKCJDYXNlICVkOlxuIiwgaSk7CgogICAgICAgICBmb3IoaW50IGk9MDtpPG47KytpKQogICAgICAgICB7CgogICAgICAgICAgICAgc2NhbmYoIiVkIiwmYVtpXSk7CiAgICAgICAgIH0KCgoKCiAgICAgaW5pdGlhbGl6ZSgxLDAsbi0xKTsKCgoKICAgICB3aGlsZShxPjApCiAgICAgewogICAgICAgICBxLS07CiAgICAgICAgIGludCBjaCx4LHksdjsKCiAgICAgICAgIHNjYW5mKCIlZCVkJWQiLCZjaCwmeCwmeSk7CiAgICAgICAgIGlmKGNoPT0wKQogICAgICAgICB7CgogICAgICAgICAgICAgc2NhbmYoIiVkIiwmdik7CiAgICAgICAgICAgICB1cGRhdGUoMSwwLG4tMSx4LTEseS0xLHYpOwoKICAgICAgICAgfQogICAgICAgICBlbHNlCiAgICAgICAgIHsKICAgICAgICAgICAgIHByaW50ZigiJWRcbiIscXVlcnkoMSwwLG4tMSx4LTEseS0xKSk7CgogICAgICAgICB9CiAgICAgfQoKICAgIH0KIH0K