#include #define fi first #define se second #define eb emplace_back #define mp make_pair using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef __int128 i128; template T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);} template T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);} template bool chmax(T &a,const S b) {return (a bool chmin(T &a,const S b) {return (a>b?a=b,1:0);} int popcnt(int x) {return __builtin_popcount(x);} int popcnt(ll x) {return __builtin_popcountll(x);} int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));} int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));} int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));} int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));} #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define ac 1 #define wa 0 typedef pair pii; typedef vector vi; typedef vector vp; int read() { int x=0,w=1; char c=getchar(); while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();} while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} return x*w; } const int N=2e5+5; int n,m,Q,b[N],bs,p[N],L,R,curac,curpen,st[N],hd[N],nxtsub[N],nxtac[N],disac[N],lstsub[N],lstac[N],pen[N],acc[N]; char tmp[5]; pii ans[N]; struct qry {int l,r,id;} q[N]; bool cmp(const qry &x,const qry &y) { return b[x.l]==b[y.l]?x.rR) pen[x]=acc[x]=0; else acc[x]=1, pen[x]=disac[hd[x]]; } void addleft(int x) { curac-=acc[p[x]], curpen-=pen[p[x]]; hd[p[x]]=x; work(p[x]); curac+=acc[p[x]], curpen+=pen[p[x]]; } void delleft(int x) { curac-=acc[p[x]], curpen-=pen[p[x]]; if(nxtsub[x]<=R) hd[p[x]]=nxtsub[x]; else hd[p[x]]=0; work(p[x]); curac+=acc[p[x]], curpen+=pen[p[x]]; } void addright(int x) { curac-=acc[p[x]], curpen-=pen[p[x]]; if(!hd[p[x]]) hd[p[x]]=x; work(p[x]); curac+=acc[p[x]], curpen+=pen[p[x]]; } void delright(int x) { curac-=acc[p[x]], curpen-=pen[p[x]]; if(x==hd[p[x]]) hd[p[x]]=0; work(p[x]); curac+=acc[p[x]], curpen+=pen[p[x]]; } signed main() { n=read(), m=read(), Q=read(); bs=sqrt(n); rep(i,1,n) b[i]=(i-1)/bs+1; rep(i,1,n) { scanf("%d%s",&p[i],tmp); if(tmp[0]=='W') st[i]=wa; else st[i]=ac; } rep(i,1,m) lstsub[i]=lstac[i]=n+1; per(i,n,1) { nxtsub[i]=lstsub[p[i]]; nxtac[i]=lstac[p[i]]; disac[i]=disac[lstsub[p[i]]]+1; lstsub[p[i]]=i; if(st[i]==ac) lstac[p[i]]=i, nxtac[i]=i, disac[i]=0; } rep(i,1,Q) q[i].l=read(), q[i].r=read(), q[i].id=i; sort(q+1,q+Q+1,cmp); L=1, R=0; rep(i,1,Q) { while(L>q[i].l) --L, addleft(L); while(Rq[i].r) R--, delright(R+1); ans[q[i].id]=pii(curac,curpen); } rep(i,1,Q) printf("%d %d\n",ans[i].fi,ans[i].se); return 0; }