#include<cstdio>
#include<cstring>
#define MAXN 1000010
char a[2][MAXN];
inline int MIN(int x, int y) {
	return x > y ? y : x;
}
struct node {
	int left, right;
};
node tree[MAXN << 2];
inline void PushUp(int mid, int L, int R, int rt) {
	tree[rt].left = tree[rt << 1].left;
	tree[rt].right = tree[rt << 1 | 1].right;
	if (tree[rt].left == mid - L + 1)
		tree[rt].left += tree[rt << 1 | 1].left;
	if (tree[rt].right == R - mid)
		tree[rt].right += tree[rt << 1].right;
}
void Build(int L, int R, int rt) {
	if (L == R) {
		if (a[0][L] == a[1][L])
			tree[rt].left = tree[rt].right = 1;
		else
			tree[rt].left = tree[rt].right = 0;
	} else {
		int mid = (L + R) >> 1;
		Build(L, mid, rt << 1);
		Build(mid + 1, R, rt << 1 | 1);
		PushUp(mid, L, R, rt);
	}
}
void Update(int x, int L, int R, int rt) {
	if (L == R) {
		if (a[0][L] == a[1][L])
			tree[rt].left = tree[rt].right = 1;
		else
			tree[rt].left = tree[rt].right = 0;
	} else {
		int mid = (L + R) >> 1;
		Build(L, mid, rt << 1);
		Build(mid + 1, R, rt << 1 | 1);
		PushUp(mid, L, R, rt);
	}
}
int Query(int x, int L, int R, int rt) {
	if (R - tree[rt].right + 1 <= x)
		return (R - tree[rt].right + 1) + tree[rt].left;
	else {
		int mid = (L + R) >> 1;
		if (x <= mid)
			return Query(x, L, mid, rt << 1);
		else
			return Query(x, mid + 1, R, rt << 1 | 1);
	}
}
int main() {
	int ca = 1;
	int ans;
	int c, la, lb, n, q;
	int cmd, id, i;
	char ch;
	scanf("%d", &c);
	while (c--) {
		scanf(" %s %s", a[0], a[1]);
		la = strlen(a[0]);
		lb = strlen(a[1]);
		n = MIN(la, lb) - 1;
		Build(0, n, 1);
		scanf("%d", &q);
		printf("Case %d:\n", ca++);
		while (q--) {
			scanf("%d", &cmd);
			if (cmd == 1) {
				scanf("%d%d %c", &id, &i, &ch);
				a[id][i] = ch;
				Update(i, 0, n, 1);
			} else {
				scanf("%d", &i);
				if (a[0][i] == a[1][i])
					ans = Query(i, 0, n, 1);
				printf("%d\n", ans);
			}
		}
	}
	return 0;
}
/*
Case 1:
2
2
2
4
2

4

*/