#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,t,m,x,y,k;
char pos;
struct Node{
ll val,lay;
}tree[100005<<2];
void push_up(ll p){
tree[p].val=tree[p<<1].val|tree[p<<1|1].val;
}
void build(ll p,ll l,ll r){
tree[p].lay=0;
if(l==r){
tree[p].val=1<<1;
return ;
}
ll mid=l+r>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
push_up(p);
}
void push_down(ll p){
if(tree[p].lay==0) return ;
tree[p<<1].lay=tree[p].lay;
tree[p<<1|1].lay=tree[p].lay;
tree[p<<1].val=tree[p].lay;
tree[p<<1|1].val=tree[p].lay;
tree[p].lay=0;
}
void update(ll p,ll l,ll r,ll L,ll R,ll k){
if(l>r||r<L) return ;
if(L<=l&&r<=R){
push_down(p);
tree[p].lay=(1<<k);
tree[p].val=(1<<k);
return ;
}
push_down(p);
ll mid=l+r>>1;
if(L<=mid) update(p<<1,l,mid,L,R,k);
if(R>mid) update(p<<1|1,mid+1,r,L,R,k);
push_up(p);
}
ll query(ll p,ll l,ll r,ll L,ll R){
if(l>R||r<L) return 0;
if(L<=l&&r<=R) return tree[p].val;
ll re=0;
push_down(p);
ll mid=l+r>>1;
if(L<=mid) re|=query(p<<1,l,mid,L,R);
if(R>mid) re|=query(p<<1|1,mid+1,r,L,R);
return re;
}
int main(){
cin>>n>>t>>m;build(1,1,n);
for(int i=1;i<=m;i++){
cin>>pos;
scanf("%lld%lld",&x,&y);
if(x>y) swap(x,y);
if(pos=='C') {
scanf("%lld",&k);
update(1,1,n,x,y,k);
}
else{
ll res=query(1,1,n,x,y),ans=0;
while(res){
if(res&1) ans++;
res>>=1;
}
printf("%lld\n",ans);
}
}
return 0;
}