#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class SegXor{
public: 
  
  //遅延用の型  
  struct T{
    Int type; //0 - empty   , 1 - update
    T():type(0){}
    T(Int type):type(type){}
  };
  
  //マージ可能な主データ型
  struct D{
    Int value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(Int value):value(value){}
  };
  
  Int n;
  vector<D> dat;
  vector<T> td;
  D returnD = D(0); // 範囲外の時に返す値。
  
  SegXor(){n=-1;}
  SegXor(Int n_){
    n=1;
    while(n < n_) n *= 2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }

  D merge(const D &a,const D &b){return a.value + b.value;}
  
  void delay(Int k,Int len){
    if(td[k].type==0) return;
    td[k].type = 0;
    
    len /= 2;
    Int l = k*2+1,r = k*2+2;
    dat[l].value = len - dat[l].value; td[l].type = !td[l].type;
    dat[r].value = len - dat[r].value; td[r].type = !td[r].type;
  }

  D write(Int k,Int len){
    dat[k].value = len - dat[k].value;
    td[k].type = !td[k].type;
    return dat[k];
  }
  
  //[a,b)の値をx変更　query(a,b,x)
  D update(Int a,Int b,bool flg=true,Int k=0,Int l=0,Int r=-1){
    if(r==-1) r=n, assert(a <= n && b <= n);
    if(r <= a||b <= l) return flg? dat[k]:returnD;
    if(a <= l && r <= b) return flg? write(k, r - l):dat[k];
    
    delay(k, r - l);
    D vl = update(a,b,flg,k*2+1,l,(l+r)/2);
    D vr = update(a,b,flg,k*2+2,(l+r)/2,r);
    if(flg) dat[k] = merge(vl, vr);
    return merge(vl, vr);
  }
  
  //[a,b)の合計値を得る　find(a,b);
  Int find(Int a,Int b){
    D res = update(a,b,0,false);
    return res.value;
  }

  P add(Int x){
    Int L = x, R = n;
    while(L + 1 < R){
      Int M = (L+R)/2;
      Int sum = find(x, M);
      (sum == M - x)?  L = M:R = M;
    }
    update(x, R);
    return P(x, R);
  }

  P sub(Int x){
    Int L = x, R = n;
    while(L + 1 < R){
      Int M = (L+R)/2;
      Int sum = find(x, M);
      (sum == 0)? L = M: R = M;
    }
    update(x, R);
    return P(x, R);
  }
};


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int Q;
  string A,B;
  cin>>Q>>A>>B;

  SegXor AxorAB(310000), AB(310000);

  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  for(Int i=0;i<(Int)A.size();i++) if(A[i] == '1') AB.add(i);
  for(Int i=0;i<(Int)B.size();i++) if(B[i] == '1') AB.add(i);
  AxorAB = AB;
  for(Int i=0;i<(Int)A.size();i++) if(A[i] == '1') AxorAB.update(i, i+1);
  
  auto calc=[&](){
    Int L = -1 , R = AxorAB.n;
    while(L+1<R){
      Int M = (L+R) / 2;
      Int sum = AxorAB.find(M, AxorAB.n);
      sum == 0? R = M: L = M;
    }
    Int a = AB.find(R, AB.n);
    Int b = max(0LL,L);
    return a + b;
  };
  
  while(Q--){
    char ch;
    cin>>ch;
    if(ch == 'Q'){cout<<calc()<<endl;continue;}
    Int x;
    cin>>x;
    
    if(ch == 'A'){
      auto p = A[x] == '0'? AB.add(x):AB.sub(x);
      AxorAB.update(p.first, p.second);
      AxorAB.update(x,x+1);
      A[x] = A[x] == '0'? '1':'0';

    }
    if(ch == 'B'){
      auto p = B[x] == '0'? AB.add(x):AB.sub(x);
      AxorAB.update(p.first, p.second);
      B[x] = B[x] == '0'? '1':'0';
    };
  }
  return 0;
}



Measured memory_bytes: 36576