#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000005

int N;
int BIT[NUM];
int A[NUM],B[NUM];
int len_A,len_B,len_max;
char buf_A[NUM],buf_B[NUM];
bool table[NUM];
set<int> B_POS,COMMON_POS;

void add(int loc,int value){

	BIT[loc] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

int getSum(int loc){

	int sum = BIT[loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}


int calc(int left,int right){
	return getSum(right)-getSum(left-1);
}

void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int loc){
	loc += N-1;

	table[loc] = (A[loc-(N-1)-1] == 1 || B[loc-(N-1)-1]);

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		table[parent] = table[2*parent+1] && table[2*parent+2];

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}

bool is_all_1(int search_left,int search_right,int node_id,int node_left,int node_right){

	if(search_right < node_left || search_left > node_right){
		return true;
	}

	if(search_left <= node_left && search_right >= node_right){
		return table[node_id];
	}

	bool is_left = is_all_1(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
	bool is_right = is_all_1(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

	return is_left && is_right;
}

int get_index(int loc){

	return loc+1;
}


int main(){

	int num_query;
	scanf("%d %s %s",&num_query,buf_A,buf_B);

	for(len_A = 0; buf_A[len_A] != '\0'; len_A++);
	for(len_B = 0; buf_B[len_B] != '\0'; len_B++);

	len_max = max(len_A,len_B);

	for(int i = 0; i < len_max; i++){
		A[i] = 0;
		B[i] = 0;
	}

	for(int i = len_A-1; i >= 0; i--){
		A[(len_A-1)-i] = buf_A[i]-'0';
	}
	for(int i = len_B-1; i >= 0; i--){
		B[(len_B-1)-i] = buf_B[i]-'0';
		if(B[(len_B-1)-i] == 1){
			B_POS.insert(get_index((len_B-1)-i));
			if(A[(len_B-1)-i] == 1){
				COMMON_POS.insert(get_index((len_B-1)-i));
			}
		}
	}

	N = 1;
	init(len_max+1);

	for(int i = 0; i <= 2*N-2; i++)table[i] = false;
	for(int i = 0; i <= len_max; i++)BIT[i] = 0;

	for(int i = 0; i < len_max; i++){
		add(get_index(i),A[i]);
		update(get_index(i));
	}

	char command[2];
	int tmp_loc,B_head_loc,tmp,COMMON_head_loc;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%s",command);

		switch(command[0]){
		case 'A':
			scanf("%d",&tmp_loc);

			if(A[tmp_loc] == 0){

				A[tmp_loc] = 1;
				add(get_index(tmp_loc),1);
				if(B[tmp_loc] == 1){
					COMMON_POS.insert(get_index(tmp_loc));
				}

			}else{ //A[tmp_loc] == 1

				A[tmp_loc] = 0;
				add(get_index(tmp_loc),-1);
				COMMON_POS.erase(get_index(tmp_loc));

			}
			update(get_index(tmp_loc));

			break;
		case 'B':
			scanf("%d",&tmp_loc);

			if(B[tmp_loc] == 0){

				B[tmp_loc] = 1;
				B_POS.insert(get_index(tmp_loc));
				if(A[tmp_loc] == 1){
					COMMON_POS.insert(get_index(tmp_loc));
				}

			}else{ //B[tmp_loc] == 1

				B[tmp_loc] = 0;
				B_POS.erase(get_index(tmp_loc));
				COMMON_POS.erase(get_index(tmp_loc));

			}
			update(get_index(tmp_loc));

			break;
		case 'Q':

			B_head_loc = *B_POS.rbegin();

			if(B_head_loc < 0){

				printf("%d\n",getSum(get_index(len_max)));

			}else{

				tmp = calc(B_head_loc+1,get_index(len_max))+B_head_loc-1;

				if(A[B_head_loc-1] == 1){

					printf("%d\n",tmp+1);

				}else{

					if(!COMMON_POS.empty()){

						COMMON_head_loc = *COMMON_POS.rbegin();

						if(is_all_1(COMMON_head_loc+1,B_head_loc,0,0,N-1)){

							printf("%d\n",tmp+1);

						}else{

							printf("%d\n",tmp);
						}

					}else{
						printf("%d\n",tmp);
					}
				}
			}

			break;
		}
	}

	return 0;
}



Measured memory_bytes: 18608