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 "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> K;
	string s, t;
	cin >> s >> t;
	N = max(s.size(), t.size());
	N++;
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	M = sqrt(N) + 1;
	while (s.size() < M*M)s.push_back('0');
	while (t.size() < M*M)t.push_back('0');
	for (auto &i : s)i -= '0';
	for (auto &i : t)i -= '0';
	vector<vector<int>>v(M, vector<int>(2));
	vector<vector<int>>one(M, vector<int>(2, -1));
	vector<vector<int>>sum(M, vector<int>(2));
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < 2; j++) {
			int nx = j;
			for (int k = 0; k < M; k++) {
				int idx = i * M + k;
				nx = nx + s[idx] + t[idx];
				if (nx == 1 && s[idx] == 0) {
					one[i][j] = idx;
				}
				sum[i][j] += nx & 1;
				nx >>= 1;
			}
			v[i][j] = nx;
		}
	}
	while (K--) {
		char a;
		cin >> a;
		if (a == 'Q') {
			int ans = 0;
			int nx = 0;
			int p = -1;
			for (int i = 0; i < M; i++) {
				ans += sum[i][nx];
				p = max(p, one[i][nx]);
				nx = v[i][nx];
			}
			int cn = 0;
			nx = 0;
			int minus = 0;
			while (p / M != cn / M) {
				minus += sum[cn / M][nx];
				nx = v[cn / M][nx];
				cn += M;
			}
			while (p >= cn) {
				nx = nx + s[cn] + t[cn];
				minus += nx & 1;
				nx >>= 1;
				cn++;
			}
			cout << ans+p-minus << endl;
			continue;
		}
		cin >> N;
		if (a == 'A') {
			s[N] ^= 1;
		}
		else {
			t[N] ^= 1;
		}
		int st = N / M;
		for (int i = 0; i < 2; i++) {
			int nx = i;
			one[st][i] = -1;
			sum[st][i] = 0;
			for (int j = 0; j < M; j++) {
				int idx = st * M + j;
				nx = nx + s[idx] + t[idx];
				if (nx == 1 && s[idx] == 0) {
					one[st][i] = idx;
				}
				sum[st][i] += nx & 1;
				nx >>= 1;
			}
			v[st][i] = nx;
		}
		
	}
}