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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct BIT{
  int n;
  vector<ll> bit;
  BIT(int size):n(size),bit(size+1,0){}

  ll sum(int i){
    if(i==-1)return 0;
    i++;
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }

  void add(int i,ll v){
    i++;
    while(i<=n){
      bit[i]+=v;
      i+=i&-i;
    }
  }

  ll lower_bound(ll w){
    if(w<=0)return 0;
    ll x=0,r=1;
    while(r<n)r<<=1;
    for(ll k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
        w-=bit[x+k];
        x+=k;
      }
    }
    return x;
  }
};

int Q,N=300010;
string A,B;
set<int> id0,id1;

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

  cin>>Q>>A>>B;
  reverse(all(A)); reverse(all(B));
  BIT bita(N),bitb(N);
  int totb=0;

  rep(i,A.size()){
    if(A[i]=='1')bita.add(i,1);
  }
  rep(i,B.size()){
    if(B[i]=='1'){
      bitb.add(i,1);
      totb++;
    }
  }
  rep(i,N){
    if(bita.sum(i)-bita.sum(i-1)==0&&bitb.sum(i)-bitb.sum(i-1)==0)id0.insert(-i);
    if(bita.sum(i)-bita.sum(i-1)==1&&bitb.sum(i)-bitb.sum(i-1)==1)id1.insert(-i);
  }

  while(Q--){
    char typ;
    cin>>typ;
    if(typ=='Q'){
      int r=bitb.lower_bound(totb);

      int idx0=-100000000,idx1=-100000000;
      if(id0.size()){
        auto it=id0.lower_bound(-r);
        idx0=-(*it);
      }

      if(id1.size()){
        auto it=id1.lower_bound(-r);
        idx1=-(*it);
      }

      if(idx1>idx0){
        cout<<bita.sum(N-1)-bita.sum(r)+r+1<<endl;
      }else{
        cout<<bita.sum(N-1)-bita.sum(r)+r<<endl;
      }
    }else{
      int i;
      cin>>i;
      int crta=bita.sum(i)-bita.sum(i-1);
      int crtb=bitb.sum(i)-bitb.sum(i-1);
      if(typ=='A'){
        if(crta==0){
          bita.add(i,1);
          if(crtb==0)id0.erase(-i);
          else id1.insert(-i);
        }else{
          bita.add(i,-1);
          if(crtb==1)id1.erase(-i);
          else id0.insert(-i);
        }
      }else{
        if(crtb==0){
          bitb.add(i,1);
          totb++;
          if(crta==0)id0.erase(-i);
          else id1.insert(-i);
        }else{
          bitb.add(i,-1);
          totb--;
          if(crta==1)id1.erase(-i);
          else id0.insert(-i);
        }
      }
    }
  }

  return 0;
}