#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 using P = pair; P op(P a,P b){ a.first += b.first; a.second += b.second; return a; } P e(){ return make_pair(0,0); } int main(){ int n,m,q; cin>>n>>m>>q; vector p(n),s(n); rep(i,n){ cin>>p[i]; p[i]--; string ss; cin>>ss; if(ss[0]=='A')s[i] = 1; else s[i] = 0; } vector> qs(n); vector l(q),r(q); rep(i,q){ cin>>l[i]>>r[i]; l[i]--,r[i]--; qs[r[i]].push_back(i); } vector ac(q),wa(q); vector> D(m,deque(1,-1)); segtree seg(n+1); rep(i,n){ if(s[i]==0){ D[p[i]].push_back(i); } else{ int cnt = D[p[i]].size() - 1; int cur = 0; while(D[p[i]].size()>1){ int u = D[p[i]].back(); D[p[i]].pop_back(); seg.set(u,make_pair(1,0)); cur++; } if(D[p[i]].back()!=-1)seg.set(D[p[i]].back(),make_pair(-cur,0)); seg.set(i,make_pair(0,1)); D[p[i]].front() = i; } rep(j,qs[i].size()){ int ii = qs[i][j]; ac[ii] = seg.prod(l[ii],n).second; wa[ii] =seg.prod(l[ii],n).first; } } rep(i,q){ cout<