#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;
		}
		
	}
}
