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<iostream>
#include<string>
#include<algorithm>
using namespace std;

#define MAX_N 500000
string A, B;
int n, c, d, e, sum;
int a[MAX_N], b[MAX_N], ab[MAX_N];
char f[MAX_N];

int main() {
	cin >> n;
	cin >> A >> B;
	d = max(A.size(), B.size()) + 1;
	for (int i = 0; i < A.size(); i++)
	{
		if (A[i] == '1') { c = 1; }
		if (A[i] == '0') { c = 0; }
		a[A.size() - 1 - i] = c;
	}
	for (int i = 0; i < B.size(); i++)
	{
		if (B[i] == '1') { c = 1; }
		if (B[i] == '0') { c = 0; }
		b[B.size() - 1 - i] = c;
	}
	for (int i = 0; i < d; i++)
	{
		ab[i] += a[i] + b[i];
		if (ab[i] >= 2) {
			ab[i] -= 2; ab[i + 1]++;
		}
	}
	for (int i = 0; i < n; i++)
	{
		cin >> f[i];
		if (f[i] == 'A') {
			cin >> e;
			if (a[e] == 1)
			{
				a[e] = 0;
				ab[e]--;
				if (ab[e] < 0)
				{
					while (e < d)
					{
						ab[e + 1]--;
						ab[e] += 2;
						if (ab[e + 1] == 0) { break; }
						e++;
					}
				}
			}
			else
			{
				a[e] = 1;
				ab[e]++;
				if (ab[e] >= 2)
				{
					while (e < d)
					{
						ab[e + 1]++;
						ab[e] -= 2;
						if (ab[e + 1] == 1) { break; }
						e++;
					}
				}
			}
		}
		if (f[i] == 'B')
		{
			cin >> e;
			if (b[e] == 1)
			{
				b[e] = 0;
				ab[e]--;
				if (ab[e] < 0)
				{
					while (e < d)
					{
						ab[e + 1]--;
						ab[e] += 2;
						if (ab[e + 1] == 0) { break; }
						e++;
					}
				}
			}
			else
			{
				b[e] = 1;
				ab[e]++;
				if (ab[e] >= 2)
				{
					while (e < d)
					{
						ab[e + 1]++;
						ab[e] -= 2;
						if (ab[e + 1] == 1) { break; }
						e++;
					}
				}
			}
		}
		if (f[i] == 'Q') {
			if (i >= 1) {
				if (f[i - 1] == 'Q') {
					cout << sum << endl; goto H;
				}
			}
			sum = 0;
			for (int j = d; j >= 0; j--)
			{
				if (a[j] != ab[j])
				{
					sum += j;
					break;
				}
				if (a[j] == 1) {
					sum++;
				}
			}
			cout << sum << endl;
		H:;
		}
	}
	return 0;
}