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

