#include <iostream>
using namespace std;
#include <string.h>
#include <stdio.h>
#define N 20005
int curt, T;

void atk2 (int x, int l, int r, int d);

struct node { int l, r, tim; } buf[4*N];
void init(int x, int l, int r) {	
	if(l==r) buf[x]=(node){l,r,0};
	else {
		int m=(l+r)/2;
		init(x*2,l,m);
		init(x*2+1,m+1,r);
		buf[x]=(node){l,r,0};
	}
}
void push(int x) {
	if(buf[x].tim == -1) return;
	if(buf[x].l == buf[x].r) return;
	int m=(buf[x].l+buf[x].r)/2;
	buf[x*2].tim = buf[x*2+1].tim = buf[x].tim;
	buf[x].tim = -1;
}
void pull(int x) {
	if(buf[x].l == buf[x].r) return;
	if(buf[x*2].tim != -1 && buf[x*2].tim <= curt && buf[x*2+1].tim!=-1 && buf[x*2+1].tim <= curt) buf[x].tim = curt;
	else buf[x].tim = -1;
}
void atk (int x, int l, int r) {
	// cout << "Before atk " << x << " " << buf[x].l << " " << buf[x].r << " " << buf[x].tim << endl;
	
	if(buf[x].l == l && buf[x].r == r && buf[x].tim <= curt && buf[x].tim != -1) buf[x].tim = curt + T;
	else if(buf[x].l == l && buf[x].r == r && buf[x].tim > curt) atk2 (x, l, r, 1);
	else {
		push(x);
		int m=(buf[x].l+buf[x].r)/2;
		if(r<=m) atk (x*2, l, r);
		else if(l>m) atk (x*2+1, l, r);
		else atk (x*2, l, m), atk (x*2+1, m+1, r);
		pull(x);
	}
	
	// cout << "After atk " << x << " " << buf[x].l << " " << buf[x].r << " " << buf[x].tim << endl;
}

struct node2 { int l, r, cnt, bg; } buf2 [4*N];
void init2 (int x, int l, int r) {
	if(l == r) buf2 [x]=(node2){l,r,0,0};
	else {
		int m=(l+r)/2;
		init2 (x*2,l,m);
		init2 (x*2+1,m+1,r);
		buf2 [x]=(node2){l,r,0,0};
	}
}
void push2 (int x) {
	if(buf2 [x].bg == 0) return;
	if(buf2 [x].l == buf2 [x].r) return;
	int m = (buf2 [x].l + buf2 [x].r)/2;
	atk2(x*2, buf2 [x].l, m, buf2 [x].bg);
	atk2(x*2+1, m+1, buf2 [x].r, buf2 [x].bg);
	buf2 [x].bg =0;
}
void atk2 (int x, int l, int r, int d) {
	// cout << "atk2: " << x << " "<< l << " " << r  << endl;
	if(buf2[x].l == l &&  buf2[x].r== r) buf2[x].bg+=d;
	else {
		push2 (x);
		int m=(buf2[x].l+buf2[x].r)/2;
		if(r<=m) atk2 (x*2,l,r,1);
		else if(l>m) atk2 (x*2+1,l,r,1);
		else atk2 (x*2,l,m,1),atk2 (x*2+1,m+1,r,1);
	}
}
int query2 (int x, int q) {
	if(buf2 [x].l == buf2 [x].r) return buf2 [x].cnt + buf2 [x].bg;
	push2 (x);
	int m=(buf2 [x].l+buf2 [x].r)/2;
	if(q<=m) return query2 (x*2, q);
	return query2 (x*2+1, q);
}
int main() {
	int n, q, cas=1, casn;
	scanf("%d", &casn);
	while(casn--) {
		scanf("%d%d%d", &n, &q, &T);
		printf("Case %d:\n", cas++);
		curt=0;
		
		memset( buf, 0, sizeof buf );
		memset( buf2, 0, sizeof buf2 );
		init (1, 1, n);
		init2(1, 1, n);
		for(int i=0; i<q; ++i) {
			char op[50];
			scanf("%s",op);
			if(op[0]=='A') {
				int l, r;
				scanf("%d%d", &l ,&r);
				atk (1, l, r);
				curt++;
			} else {
				int pos;
				scanf("%d", &pos);
				printf("%d\n", query2 (1, pos));
			}
			
		}
	}
	return 0;
}