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