Problem: Ikta, who was in trouble because he couldn't come up with an idea for the problem to be presented at the training camp of the programming contest, consulted with a friend one day.

Mr. Ikta "I want to create a problem that cannot be solved without using such an algorithm. Is there anything?"

Friend "Then why not think about something like this?"

In this way, the friend came up with the idea that would be the basis for the following problems.

Given binary numbers A and B, process the following query.

* Output query: Outputs the number of 1s when max {x is expressed in binary | A ≤ x <A + B}
* A change query: Inverts the i-th bit (0-origin) from the least significant bit of A
* B change query: Inverts the i-th bit (0-origin) from the least significant bit of B



Note that the i-bit is represented by 0-origin. That is, the 0th bit from the least significant bit of A represents the least significant bit.



Input

The input is given in the following format.


N A B
Q1
...
QN

The number of queries N, binary numbers A and B are given in the first line.

The following query is given in the 2nd to N + 1 lines.

* Q
* A i
* B i



Q represents the output query, and A i and B i represent the change query that inverts the i-th bit from the least significant bit of A and the i-th bit from the least significant bit of B, respectively.

Constraints

Each variable being input satisfies the following constraints.

* 1 ≤ N <300,000
* 1 ≤ | A |, | B | ≤ 300,000 (| A | is the length of A)
* In the query A i, 0 ≤ i <| A |
* In the query B i 0 ≤ i <| B |
* B can never be 0

Output

Print the answer on one line for each output query.

Examples

Input

4 10000 00101
Q
A 0
B 1
Q


Output

3
4


Input

9 0110111101 0010100111
Q
B 4
Q
A 4
Q
B 9
Q
A 8
Q


Output

9
9
9
10
9

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define INF 1<<19
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<19;
	int dp[1<<20];
	int cnt[1<<20];
	segtree(){
		for(int i=0;i<N*2;i++){
			dp[i]=INF;
			cnt[i]=0;
		}
	}
	void update(int k,int v){
		k+=N-1;
		dp[k]=v;
		if(v==INF){
			cnt[k]=0;
		}else{
			cnt[k]=1;
		}
		while(k>0){
			k=(k-1)/2;
			dp[k]=min(dp[k*2+1],dp[k*2+2]);
			cnt[k]=cnt[k*2+1]+cnt[k*2+2];
		}
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return INF;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		return min(vl,vr);
	}

	int query2(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return cnt[k];
		int mid=(l+r)/2;
		int vl=query2(a,b,k*2+1,l,mid);
		int vr=query2(a,b,k*2+2,mid,r);
		return vl+vr;
	}
};

segtree seg[4];
int bit[300005];

int main(void){
	int q;
	string a,b;
	cin >> q >> a >> b;
	int n2=a.size();
	int m2=b.size();
	for(int i=0;i<n2;i++){
		if(a[i]=='1'){
			bit[i+max(0,m2-n2)]^=1;
		}
	}
	for(int i=0;i<m2;i++){
		if(b[i]=='1'){
			bit[i+max(0,n2-m2)]^=2;
		}
	}
	int n=max(n2,m2);
	for(int i=0;i<n;i++){
		seg[bit[i]].update(i,i);
	}
	for(int i=0;i<q;i++){
		char c;
		scanf(" %c",&c);
		if(c=='Q'){
			int pos[4];
			for(int j=0;j<4;j++){
				pos[j]=seg[j].dp[0];
			}
			if(min(pos[1],pos[2])>pos[3]){
				printf("%d\n",n-pos[3]);
			}else if(pos[1]<pos[2]){
				if(seg[0].query(pos[1],n)>seg[3].query(pos[1],n)){
					printf("%d\n",n-pos[1]);
				}else if(seg[2].query(pos[1],n)>seg[3].query(pos[1],n)){
					int v=seg[3].query(pos[1],n);
					printf("%d\n",n-v+seg[1].query2(0,v));
				}else{
					int v=seg[2].query(pos[1],n);
					if(seg[0].query(v,n)>seg[3].query(v,n)){
						printf("%d\n",n-min(v,n)+seg[1].query2(0,v));
					}else{
						printf("%d\n",max(n-min(v,n)+seg[1].query2(0,v)-1,0));
					}
				}
			}else{
				if(seg[0].query(pos[2],n)>seg[3].query(pos[2],n)){
					printf("%d\n",n-pos[2]);
				}else{
					printf("%d\n",n-pos[2]-1);
				}
			}
		}else{
			int a;
			scanf("%d",&a);
			a=n-a-1;
			seg[bit[a]].update(a,INF);
			if(c=='A'){
				bit[a]^=1;
			}else{
				bit[a]^=2;
			}
			seg[bit[a]].update(a,a);
		}
	}
	return 0;
}