#include
#include
#include
#include
#include
using namespace std;
#define maxn 210000
int vis[maxn<<2],tree[maxn<<2];
void pushup(int rt)
{
tree[rt]=(tree[rt<<1] | tree[rt<<1|1]);
}
void pushdown(int rt)
{
if(vis[rt])
{
tree[rt<<1]=tree[rt<<1|1]=tree[rt];
vis[rt<<1]=vis[rt<<1|1]=vis[rt];
vis[rt]=0;
}
}
void build(int rt,int l,int r)
{
int m=(l+r)>>1;
tree[rt]=1;
vis[rt]=0;
if(l==r)
{
return;
}
build( rt<<1 , l , m );
build( rt<<1|1 , m+1 , r );
pushup(rt);
}
void update(int num,int s,int e,int l,int r,int val)
{
int mid=(s+e)>>1;
if(l<=s && r>=e)
{
vis[num]=1;
tree[num] = 1<<(val-1);
return;
}
pushdown(num);
if(l<=mid)update(num<<1,s,mid,l,r,val);
if(r>mid)update(num<<1|1,mid+1,e,l,r,val);
pushup(num);
}
int query(int num,int s,int e,int l,int r)
{
int mid=(s+e)>>1;
if(s==l && e==r)
return tree[num];
pushdown(num);
if(r<=mid)return query(num<<1,s,mid,l,r);
else if(l>mid)return query(num<<1|1,mid+1,e,l,r);
else
return (query(num<<1,s,mid,l,mid) | query(num<<1|1,mid+1,e,mid+1,r));
}
int main()
{
int n,t,m;
int a,b,c;
char op[10];
while(~scanf("%d%d%d",&n,&t,&m))
{
build(1,1,n);
while(m--)
{
scanf("%s",op);
if(op[0]=='C')
{
scanf("%d%d%d",&a,&b,&c);
if(a>b)
swap(a,b);
update(1,1,n,a,b,c);
}
else
{
scanf("%d%d",&a,&b);
int ans=0;
if(a>b)
swap(a,b);
int k=query(1,1,n,a,b);
while(k)
{
if(k&1)
ans++;
k=(k>>1);
}
printf("%d\n",ans);
}
}
}
return 0;
}