#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;

const int INF = 1<<28;

struct Node {
    using NP = Node*;

    int lz;
    int f0, f1;
    int a0, a1;
    int di, bsm;

    void update() {
        int lsz = sz/2;
        f0 = min(l->f0, lsz + r->f0);
        f1 = min(l->f1, lsz + r->f1);
        di = max(l->di, lsz + r->di);
        a0 = max(l->a0, lsz + r->a0);
        a1 = max(l->a1, lsz + r->a1);
        bsm = l->bsm + r->bsm;
    }
    void lzdata(int x) {
        lz = x;
        if (x == 0) {
            f0 = 0;
            f1 = INF;
            di = a1;
            bsm = 0;
        } else {
            f0 = INF;
            f1 = 0;
            di = a0;
            bsm = sz;
        }
    }
    void push() {
        if (lz != -1) {
            l->lzdata(lz);
            r->lzdata(lz);
            lz = -1;
        }
    }

    int search0(int k) {
        if (sz <= k) return INF;
        if (k <= 0) return f0;
        push();
        return min(l->search0(k), sz/2 + r->search0(k - sz/2));
    }

    int search1(int k) {
        if (sz <= k) return INF;
        if (k <= 0) return f1;
        push();
        return min(l->search1(k), sz/2 + r->search1(k - sz/2));
    }

    void set(int a, int b, int x) {
        if (b <= 0 or sz <= a) return;
        if (a <= 0 and sz <= b) {
            lzdata(x);
            return;
        }
        push();
        l->set(a, b, x);
        r->set(a - sz/2, b - sz/2, x);
        update();
    }

    void seta(int k, int x) {
        if (sz == 1) {
            if (!x) {
                a0 = 0;
                a1 = -INF;
            } else {
                a0 = -INF;
                a1 = 0;
            }
            if (x != lz) {
                di = 0;
            } else {
                di = -INF;
            }
            return;
        }
        push();
        if (k < sz/2) {
            l->seta(k, x);
        } else {
            r->seta(k - sz/2, x);
        }
        update();
    }
    int get(int a, int b) {
        if (b <= 0 or sz <= a) return 0;
        if (a <= 0 and sz <= b) {
            return bsm;
        }
        push();
        return l->get(a, b) + r->get(a - sz/2, b - sz/2);
    }
    NP l, r;
    int sz;

    Node(int sz, bool a[]) : sz(sz) {
        lz = -1;
        if (sz == 1) {
            lz = a[0];
            if (!a[0]) {
                a0 = 0;
                a1 = -INF;
                f0 = 0;
                f1 = INF;
                di = -INF;
                bsm = 0;
            } else {
                a0 = -INF;
                a1 = 0;
                f0 = INF;
                f1 = 0;
                di = -INF;
                bsm = 1;
            }
            return;
        }
        l = new Node(sz/2, a);
        r = new Node(sz - sz/2, a + sz/2);
        update();
    }
};

const int MM = 300300;
bool a[MM], b[MM];
Node* tr;

void add1(int k) {
    int u = tr->search0(k);
//    printf("add %d %d\n", k, u);
    tr->set(u, u+1, 1);
    tr->set(k, u, 0);
}

void dec1(int k) {
    int u = tr->search1(k);
//    printf("dec %d %d\n", k, u);
    tr->set(u, u+1, 0);
    tr->set(k, u, 1);
}

int main() {
    int n;
    string as, bs;
    cin >> n >> as >> bs;
    reverse(as.begin(), as.end());
    reverse(bs.begin(), bs.end());
    for (int i = 0; i < (int)as.size(); i++) {
        a[i] = (as[i] == '1');
    }
    tr = new Node(MM, a);
    for (int i = 0; i < (int)bs.size(); i++) {
        b[i] = (bs[i] == '1');
        if (b[i]) add1(i);
    }
    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        if (c == 'Q') {
            int u = tr->di;
            cout << tr->get(u+1, MM) + u << endl;
        } else if (c == 'A') {
            int k;
            cin >> k;
            if (!a[k]) {
                a[k] = true;
                tr->seta(k, 1);
                add1(k);
            } else {
                a[k] = false;
                tr->seta(k, 0);
                dec1(k);
            }
        } else if (c == 'B') {
            int k;
            cin >> k;
            if (!b[k]) {
                b[k] = true;
                add1(k);
            } else {
                b[k] = false;
                dec1(k);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 41732