#include <bits/stdc++.h>
#define ll long long
#define OO 1000000000
using namespace std;

int suf1[100001];
int suf2[100001];

int cum1[100001];
int cum2[100001];

pair<int, int> trailing(int l1, int r1, int l2, int r2){
    int t1, t2;
    if(r1 - suf1[r1-1] >= l1)
        t1 = suf1[r1-1];
    else
        t1 = suf1[r1-1] - suf1[l1-1] + 1;
    if(r2 - suf2[r2-1] >= l2)
        t2 = suf2[r2-1];
    else
        t2 = suf2[r2-1] - suf2[l2-1] + 1;
    return {t1, t2};
}

pair<int, int> cum(int l1, int r1, int l2, int r2){
    return {(cum1[r1-1] - (l1 == 1 ? 0 : cum1[l1-2]))
           , (cum2[r2-1] - (l2 == 1 ? 0 : cum2[l2-2]))};
}
int main(){
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    for(int i = 0;i < a.size();i++){
        if(i)
            cum1[i] += cum1[i-1];

        cum1[i] += (a[i] != 'A' ? 1 : 0);
        if(a[i] == 'A'){
            suf1[i] += 1;
            if(i)
                suf1[i] += suf1[i-1];
        }

    }
    for(int i = 0;i < b.size();i++){
        if(i)
            cum2[i] += cum2[i-1];

        cum2[i] += (b[i] != 'A' ? 1 : 0);
        if(b[i] == 'A'){
            suf2[i] += 1;
            if(i)
                suf2[i] += suf2[i-1];
        }
//        cout << suf2[i] << endl;
    }
    int q;
    cin >> q;
    int l1, l2, r1, r2;
    for(int i = 0;i < q;i++){
        cin >> l1 >> r1 >> l2 >> r2;
//  //      cout << a.substr(l1-1, r1-l1+1)<< ' ' << b.substr(l2-1, r2-l2+1) << endl;
        pair<int, int> tr = trailing(l1, r1, l2, r2);
//        cout << tr.first <<  ' '  << tr.second << endl;
        pair<int, int> cc = cum(l1, r1, l2, r2);
        bool ok = 1;
        if(tr.second > tr.first)ok = 0;
        tr.first -= tr.second;
        if((tr.first)%3 || (tr.first && !cc.first && cc.second))cc.first += 2;
        if(cc.first > cc.second)ok = 0;
        if(((cc.second - cc.first) & 1) || (cc.second && !cc.first))ok = 0;

        cout << ok;
    }
}

//Copyright(c)2018 Mstdream
#include<bits/stdc++.h>
using namespace std;

inline void splay(int &v){
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
const int N=100010;
char s[N],t[N];
int a[N],b[N],suma[N],sumb[N],lta[N],ltb[N],Q;
int main(){
	scanf("%s%s",s+1,t+1);
	int n=strlen(s+1),m=strlen(t+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='A')a[i]=0;
		else a[i]=1;
		suma[i]=suma[i-1]+a[i];
		if(a[i]==1)lta[i]=i;
		else lta[i]=lta[i-1];
	}
	for(int i=1;i<=m;i++){
		if(t[i]=='A')b[i]=0;
		else b[i]=1;
		sumb[i]=sumb[i-1]+b[i];
		if(b[i]==1)ltb[i]=i;
		else ltb[i]=ltb[i-1];
	}
	splay(Q);
	for(;Q--;){
		int l,r,L,R;
		splay(l),splay(r),splay(L),splay(R);
		int f=suma[r]-suma[l-1],g=r-lta[r];
		int p=sumb[R]-sumb[L-1],q=R-ltb[R];
		if(!f)g=r-l+1;if(!p)q=R-L+1;
		bool flag=0;
		if(p>=f&&g>=q&&(p-f)%2==0){
			if(!f){
				if(!p){
					if((g-q)%3==0)flag=1;
				}
				if(p){
					if(g>q)flag=1;
				}
			}
			else{
				if((g-q)%3!=0)f+=2;
				if(p>=f)flag=1;
			}
		}
		putchar(flag?'1':'0');
	}
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
//#define int lld
typedef int64_t lld;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
//#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
    return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
}
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T, N> &c ) {
     return _out(s,c.begin(),c.end());
}
inline char readchar() {
	const int S = 1<<20; // buffer size
	static char buf[S], *p = buf, *q = buf;
	if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
	return *p++;
}
inline void input(int &_x){
    _x = 0;
    int _tmp = 1; char _tc = readchar();
    while(_tc < '0' || _tc > '9') _tc = readchar();
    while(_tc >= '0' && _tc <= '9') _x = (_x<<1)+(_x<<3)+(_tc-48), _tc = readchar();
}
inline void output(int _x){
    char _buff[20]; int _f = 0;
    if(_x == 0) putchar('0');
    while(_x > 0){
            _buff[_f++] = _x%10+'0';
            _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
            putchar(_buff[_f]);
  putchar('\n');
}

vector<int> u, v, uu, vv;
signed main(){jizz; //freopen("test.in", "r", stdin);
#ifdef LOCAL
freopen("test.in", "r", stdin);
#endif
    string s, t;
    cin >> s >> t; u.pb(0), v.pb(0); uu.pb(0); vv.pb(0);
    for(auto c: s)u.pb(c != 'A');
    for(auto c: t)v.pb(c != 'A');
    for(auto c: s)uu.pb(c == 'A'?1+uu.back():0);
    for(auto c: t)vv.pb(c == 'A'?1+vv.back():0);
    for(int i = 1; i < u.size(); i++)u[i]+=u[i-1];
    for(int i = 1; i < v.size(); i++)v[i]+=v[i-1];
    int q;
    cin >> q;
    while(q--){
        int a, b, c, d;
        cin >> a >> b >> c >> d; //cout << min(uu[b], b-a+1) << min(vv[d], d-c+1)  << endl;
        if((v[d]-v[c-1]) < (u[b]-u[a-1]))putchar('0');
        else if(((v[d]-v[c-1]) - (u[b]-u[a-1]))&1)putchar('0');
        else if(min(uu[b], b-a+1) < min(vv[d], d-c+1))putchar('0');
        else if(u[b]-u[a-1] == 0 && (v[d]-v[c-1]) > 0 && min(uu[b], b-a+1) == min(vv[d], d-c+1))putchar('0');
        else if((v[d]-v[c-1]) > (u[b]-u[a-1]) && min(uu[b], b-a+1) > min(vv[d], d-c+1))putchar('1');
        else if((min(uu[b], b-a+1)-min(vv[d], d-c+1))%3 != 0)putchar('0');
        else putchar('1');
    }
    //cout << u << v << endl;
}

//be name khoda

#include <bits/stdc++.h>
using namespace std;

#define sz(x) ((int)x.size())
#define rep(i, n) for(int i = 0; i < (n); i++)
#define res(i, s) for(int i = 0; i < (sz(s)); i++)
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define clear(a) (memset((a),0,sizeof(a)))

typedef long long ll;

const int N = 1e5 + 123;

int pre[N][2], las[N][2];

void out(int a)
{
	putchar((a ? '1' : '0'));
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s[2];
	cin >> s[0] >> s[1];
	rep(ind, 2)
		res(i, s[ind])
		{
			pre[i + 1][ind] = pre[i][ind] + (s[ind][i] != 'A');
			las[i + 1][ind] = las[i][ind];
			if(s[ind][i] != 'A')
				las[i + 1][ind] = i + 1;
		}
	int q;
	cin >> q;
	// for(int j = 0; j < 2; j++)
	// 	for(int i = 0; i <= sz(a); i++)
	// 		cout << i << ' ' << j << ' ' << pre[i][j] << ' ' << pra[i][j] << ' ' << las[i][j] << endl;
	while(q--)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int ta = pre[b][0] - pre[a - 1][0];
		int tb = pre[d][1] - pre[c - 1][1];
		int la = b - max(a - 1, las[b][0]);
		int lb = d - max(c - 1, las[d][1]);
		// cout << ta << ' ' << tb << ' ' << la << ' ' << lb << endl;
		if(ta > tb or ta % 2 != tb % 2 or lb > la)
			out(0);
		else if(ta == 0 && la == lb && ta != tb)
			out(0);
		else
		{
			int d = (tb - ta) / 2;
			if(d >= 1 or la % 3 == lb % 3)
				out(1);
			else
				out(0);
		}
	}
	return 0;
}

#include <iostream>
#include <string>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<int> sones;
ordered_set<int> tones;
int get_suff (const ordered_set<int> &ones, int l, int r) {
  auto ub = ones.upper_bound(r);
  if (ub == ones.begin()) {
    return r - l + 1;
  }

  int lo = *prev(ub);
  if (lo < l) {
    return r - l + 1;
  }

  return r - lo;
}

int get_ones (const ordered_set<int> &ones, int l, int r) {
  return ones.order_of_key(r + 1) - ones.order_of_key(l);
}

bool can (int s1, int ss, int t1, int ts) {
  if (s1 == 0 && t1 != 0) {
    s1 += 2;
    if (ss <= ts) return 0;
    ss = ts;
  }
  if (s1 % 2 != t1 % 2) return 0;
  if (ss < ts) return 0;
  if (s1 > t1) return 0;
  if (s1 == t1 && (ss % 3 != ts % 3)) return 0;
  return 1;
}

bool query (int a, int b, int c, int d) {
  return can(get_ones(sones, a, b),
             get_suff(sones, a, b),
             get_ones(tones, c, d),
             get_suff(tones, c, d));
}

int main () {
  ios::sync_with_stdio(false);

  string s, t;
  cin >> s >> t;

  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] != 'A') {
      sones.insert(i + 1);
    }
  }

  for (int i = 0; i < (int) t.size(); i++) {
    if (t[i] != 'A') {
      tones.insert(i + 1);
    }
  }

  int queryc;
  cin >> queryc;
  for (int i = 0; i < queryc; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << query(a, b, c, d);
  }
  cout << endl;
}

/**
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
      AnTi-MiRaGe on Anti-Mage xD
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <memory.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define show puts("Debug")

using namespace std;

const int N = 1e5 + 5;

string a, b, ans;

int pref[3][N], pr[3][N];

main()
{
    cin >> a >> b;
    a = ' ' + a;
    b = ' ' + b;
    for (int i = 1; i < sz(a); i++)
    {
        pref[1][i] = pref[1][i - 1] + (a[i] == 'B' || a[i] == 'C');
        if (a[i] != 'A')
            pr[1][i] = 0;
        else
            pr[1][i] = pr[1][i - 1] + 1;
    }
    for (int i = 1; i < sz(b); i++)
    {
        pref[2][i] = pref[2][i - 1] + (b[i] == 'B' || b[i] == 'C');
        if (b[i] != 'A')
            pr[2][i] = 0;
        else
            pr[2][i] = pr[2][i - 1] + 1;
    }
    int q, l, r, L, R;
    cin >> q;
    while (q--)
    {
        scanf("%d%d%d%d", &l, &r, &L, &R);

        if ( min(r - l + 1, pr[1][r]) >= min(R - L + 1, pr[2][R]) )
        {
            int need = ( (min(r - l + 1, pr[1][r]) -  min(R - L + 1, pr[2][R]) ) % 3 == 0 ? 0 : 2);

            if ( (pref[1][r] - pref[1][l - 1] + need) == 0 && min(r - l + 1, pr[1][r]) -  min(R - L + 1, pr[2][R]) == 0 )
            {
                if ( (pref[2][R] - pref[2][L - 1]) == 0 )
                    ans += '1';
                else
                    ans += '0';
            }
            else if ( (pref[2][R] - pref[2][L - 1]) >= (pref[1][r] - pref[1][l - 1] + need) &&  ( (pref[2][R] - pref[2][L - 1]) - (pref[1][r] - pref[1][l - 1] + need) ) % 2 == 0 )
                ans += '1';
            else
                ans += '0';
        }
        else
            ans += '0';
    }
    cout << ans << endl;
}

//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s,t;cin>>s>>t;
  ll n=s.size(),m=t.size();
  vector<ll>vs(n+1),vt(m+1);
  rep(i,0,n)vs[i+1]=vs[i]+(s[i]!='A');
  rep(i,0,m)vt[i+1]=vt[i]+(t[i]!='A');
  vector<ll>ps(n),pt(m);
  {
    ll pre=-1;
    rep(i,0,n){
      if(s[i]!='A')pre=i;
      ps[i]=pre;
    }
    pre=-1;
    rep(i,0,m){
      if(t[i]!='A')pre=i;
      pt[i]=pre;
    }
  }
  //debug(ps,n);
  ll q;cin>>q;
  string ret;
  while(q--){
    ll a,b,c,d;cin>>a>>b>>c>>d;a--;b--;c--;d--;
    ll xs=vs[b+1]-vs[a],xt=vt[d+1]-vt[c];
    ll rs=b-max(a-1,ps[b]),rt=d-max(c-1,pt[d]);
    //cout<<xs spa xt spa rs spa rt<<endl;
    bool sw=true;
    if(xs>xt||xs%2!=xt%2)sw=false;
    if(rs<rt)sw=false;
    if(xs==0&&xt>0&&rs==rt)sw=false;
    if(xs==xt&&rs%3!=rt%3)sw=false;
    ret+=char('0'+sw);
  }
  cout<<ret<<endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;

const int N=100010;
char a[N], b[N];
int n, m;
int s[N], t[N], prea[N], preb[N];

void yes() {
    putchar('1');
}
void no() {
    putchar('0');
}
int main() {
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    n = strlen(a + 1);
    m = strlen(b + 1);
    for (int i = 1; i <= n; ++i) {
        s[i] = s[i - 1] + (a[i] != 'A');
        if (a[i] != 'A') prea[i] = 0;
        else prea[i] = prea[i - 1] + 1;
    }
    for (int i = 1; i <= m; ++i) {
        t[i] = t[i - 1] + (b[i] != 'A');
        if (b[i] != 'A') preb[i] = 0;
        else preb[i] = preb[i - 1] + 1;
    }
    int Q;
    scanf("%d", &Q);
    while (Q--) {
        int l, r, h, g;
        scanf("%d%d%d%d", &l, &r, &h, &g);
        int len1 = r - l + 1, len2 = g - h + 1;
        int tot1 = s[r] - s[l - 1], tot2 = t[g] - t[h - 1];
        int a1 = len1 - tot1, a2 = len2 - tot2;
        int suf1 = min(a1, prea[r]), suf2 = min(a2, preb[g]);
        if (tot1 > tot2 || tot1 % 2 != tot2 % 2) {
            no();
            continue;
        }
        if (tot1 == tot2) {
            if (suf1 < suf2 || suf1 % 3 != suf2 % 3) no();
            else yes();
        } else {
            if (suf1 > suf2) yes();
            else if (suf1 < suf2) no();
            else {
                if (tot1 > 0) yes();
                else no();
            }
        }
    }
    puts("");
    return 0;
}

#include<bits/stdc++.h>

#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define sz(a) ((int)a.size())
#define x first
#define y second

using namespace std;

typedef double DO;
typedef long long INT;
typedef pair<int, int> pii;
typedef vector<int> VI;

#define NN 100011
char s[NN], t[NN];
int q;
int prv[NN][2];
int cnt_A[NN][2];
int cnt_B[NN][2];

void pre(char *s, int k) {
    for(int i=1; s[i]; i++) {
        cnt_A[i][k] = cnt_A[i-1][k];
        cnt_B[i][k] = cnt_B[i-1][k];
        if(s[i] == 'A') cnt_A[i][k]++, prv[i][k] = prv[i-1][k];
        else cnt_B[i][k]++, prv[i][k] = i;
    }
}

inline int calc(int &a, int &b, int &c, int &d) {
    a--; c--;
    int A = cnt_B[b][0] - cnt_B[a][0];
    int B = cnt_B[d][1] - cnt_B[c][1];
    if(A>B or B+A&1) return 0;

    int C = b-max(a, prv[b][0]);
    int D = d-max(c, prv[d][1]);
    if(C < D) return 0;
    if(A<B) {
        return C != D or A;
    }
    else {
        return (C-D)%3==0;
    }
}

int solve() {
    scanf("%s %s", s+1, t+1);
    pre(s, 0);
    pre(t, 1);
    cin >> q;
    while(q--) {
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        printf("%d", calc(a, b, c, d));
    }
}
int main() {
#ifndef	ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
    solve();
	return 0;
}

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int M = 1e5 + 5, INF = 0x3f3f3f3f;
int sum[M], sum1[M];
int Sa[M], Ta[M];
char A[M], B[M];
int main() {
    scanf("%s%s", A + 1, B + 1);
    int n = strlen(A + 1), m = strlen(B + 1);
    for(int j = 1; j <= n; j++) {
        if(A[j] == 'A') {
            Sa[j] = Sa[j - 1] + 1;
            sum[j] = sum[j - 1];
        } else {
            Sa[j] = 0;
            sum[j] = sum[j - 1] + 1;
        }
    }
    for(int j = 1; j <= m; j++) {
        if(B[j] == 'A') {
            Ta[j] = Ta[j - 1] + 1;
            sum1[j] = sum1[j - 1];
        } else {
            Ta[j] = 0;
            sum1[j] = sum1[j - 1] + 1;
        }
    }
    int q;
    scanf("%d", &q);
    while(q--) {
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        int x = (sum[b] - sum[a - 1]) & 1, y = (sum1[d] - sum1[c - 1]) & 1;
        int Sb = (sum[b] - sum[a - 1]), Tb = (sum1[d] - sum1[c - 1]);
        int SA = min(Sa[b], b - a + 1), TA = min(Ta[d], d - c + 1);
        if((SA - TA) % 3) Sb += 2;
        if(Sb > Tb || SA < TA) printf("0");
        else if (SA == TA && Sb == 0 && Tb) printf("0");
        else if(x == y) printf("1");
        else printf("0");
    }
    printf("\n");
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 1e6;
const ll LINF = (ll) 1e18 + 1e9;
const ld EPS = (ld) 1e-7;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; ++(i))
#define per(i, f, t) for (auto i = (f); i >= (t); --(i))

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

void add(ll &x, ll y) {
    x += y;
    if (x >= MOD) x -= MOD;
    if (x < 0) x += MOD;
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = (int) 1e5 + 123;

int n, m, q;
string s, t;
int sb[N], tb[N];
int s_a[N], t_a[N];

int get(int *a, int l, int r) {
    int res = a[r];
    if (l > 0) res -= a[l - 1];
    return res;
}

void run() {
    cin >> s >> t;
    n = sz(s);
    m = sz(t);
    for (auto &c : s) if (c == 'C') c = 'B';
    for (auto &c : t) if (c == 'C') c = 'B';
    rep(i, 0, n) if (s[i] == 'B') sb[i]++;
    rep(i, 1, n) sb[i] += sb[i - 1];
    rep(i, 0, m) if (t[i] == 'B') tb[i]++;
    rep(i, 1, m) tb[i] += tb[i - 1];

    rep(i, 0, n) {
        if (s[i] == 'B') {
            s_a[i] = 0;
            continue;
        }
        s_a[i] = 1;
        if (i > 0) s_a[i] += s_a[i - 1];
    }
    rep(i, 0, m) {
        if (t[i] == 'B') {
            t_a[i] = 0;
            continue;
        }
        t_a[i] = 1;
        if (i > 0) t_a[i] += t_a[i - 1];
    }

    cin >> q;
    while (q--) {
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        l1--; r1--; l2--; r2--;
        int b1 = get(sb, l1, r1);
        int b2 = get(tb, l2, r2);
        if (b1 % 2 != b2 % 2) {
            cout << "0";
            continue;
        }
        if (b1 > b2) {
            cout << "0";
            continue;
        }

        if (b2 > b1) {
            int cnt_s = min(r1 - l1 + 1, s_a[r1]);
            int cnt_t = min(r2 - l2 + 1, t_a[r2]);
            if (cnt_s == cnt_t && cnt_s == r1 - l1 + 1) {
                cout << "0";
                continue;
            }
            if (cnt_s >= cnt_t) {
                cout << "1";
                continue;
            }

            cout << "0";
        } else {
            int cnt_s = min(r1 - l1 + 1, s_a[r1]);
            int cnt_t = min(r2 - l2 + 1, t_a[r2]);
            if (cnt_s >= cnt_t && cnt_s % 3 == cnt_t % 3) {
                cout << "1";
                continue;
            }

            cout << "0";
        }
    }
}

#include <bits/stdc++.h>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (auto I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORD(I, A, B) for (int I = (A); I >= (B); --I)
#define MAX(A, B) (A = max(A, B))
#define MIN(A, B) (A = min(A, B))
#define SZ(C) ((int) C.size())
#define ALL(C) (C).begin(), (C).end()

using ll = long long;
const int INF = 1e9;

using namespace std;

const int N = 1e5 + 5;

string s[2];
int q;
int cnt[2][N], last[2][N];

int solve() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  int trailing_a_diff = min(last[0][b], b - a + 1) - min(last[1][d], d - c + 1);
  int bc0 = cnt[0][b] - cnt[0][a - 1];
  int bc1 = cnt[1][d] - cnt[1][c - 1];
  int bc_diff = bc0 - bc1;
  if (trailing_a_diff < 0) return 0;
  if (bc_diff % 2 != 0) return 0;
  if (bc_diff > 0) return 0;
  if (bc_diff == 0) {
    if (trailing_a_diff > 0 && trailing_a_diff % 3 != 0) return 0;
  }
  if (bc_diff < 0) {
    if (trailing_a_diff > 0) {
    } else if (bc0 == 0) return 0;
  }
  return 1;
}

int main() {
  cin >> s[0] >> s[1] >> q;
  REP(i, 2) FOR(j, 1, SZ(s[i])) {
    cnt[i][j] = cnt[i][j - 1] + (s[i][j - 1] != 'A');
    last[i][j] = (s[i][j - 1] == 'A' ? last[i][j - 1] + 1 : 0);
  }

  REP(zz, q) cout << solve(); cout << endl;

  return 0;
}

#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 100005
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
using namespace std;

char s[N], t[N];
int a[N], b[N], aa[N], bb[N];

int code(char x) {
	return x != 'A';
}

int main(){
	scanf("%s %s", s, t);

	int sl = strlen(s);
	int tl = strlen(t);

	FI(i, 1, sl) {
		a[i] = a[i - 1] + code(s[i - 1]);
		aa[i] = aa[i - 1];
		if(code(s[i - 1])) aa[i] = i;
	}

	FI(i, 1, tl) {
		b[i] = b[i - 1] + code(t[i - 1]);
		bb[i] = bb[i - 1];
		if(code(t[i - 1])) bb[i] = i;
	}

	int q;
	scanf("%d", &q);

	while(q--) {
		int al, ar, bl, br;
		scanf("%d %d %d %d", &al, &ar, &bl, &br);

		int alen = ar - al + 1;
		int blen = br - bl + 1;
		int ah = min(ar - aa[ar], alen);
		int bh = min(br - bb[br], blen);

		if (ah < bh) {
			printf("0");
			continue;
		}

		if (ah == bh) {
			ar -= ah;
			br -= bh;

			int as = a[ar] - a[al - 1];
			int bs = b[br] - b[bl - 1];

			if (as > bs || (bs - as) % 2 || !as && as != bs) {
				printf("0");
			}else printf("1");

			continue;
		}

		ar -= ah;
		br -= bh;

		int as = a[ar] - a[al - 1] + ((ah - bh) % 3 ? 2 : 0);
		int bs = b[br] - b[bl - 1];

		if (as > bs || (bs - as) % 2) {
			printf("0");
		}else{
			if (!as && as != bs && as + 2 > bs) printf("0");
			else printf("1");
		}
	}

	printf("\n");
}

#include <bits/stdc++.h>

using std::ios_base;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::fixed;

using std::vector;
using std::string;
using std::stack;
using std::queue;
using std::deque;
using std::map;
using std::set;
using std::unordered_map;
using std::unordered_set;

using std::sort;
using std::reverse;
using std::nth_element;

#define pb push_back
#define mp make_pair
#define all(x) x.begin, x.end()

const int MAXN = 100005;
const int INF = 1e9;
const int MOD = 1e9+7;
const int64_t L_INF = 4e18;

struct Node {
    int cntA, cntB, cntC;
    int endA;
    int size;
};

int q;
string s, t;
Node treeS[4 * MAXN], treeT[4 * MAXN];

Node union_nodes(const Node &v, const Node &u) {
    int endA = u.endA;
    if (u.endA == u.size)
        endA += v.endA;
    return Node{v.cntA + u.cntA, v.cntB + u.cntB, v.cntC + u.cntC, endA, v.size + u.size};
}

void print_node(const Node &v) {
    cerr << v.cntA << ' ' << v.cntB << ' ' << v.cntC << ' ' << v.endA << ' ' << v.size << '\n';
}

void build(int v, int tl, int tr, Node* tree, const string& str) {
    if (tr - tl == 1) {
        tree[v] = Node{str[tl] == 'A', str[tl] == 'B', str[tl] == 'C', str[tl] == 'A', 1};
        //print_node(tree[v]);
        return;
    }
    int tm = (tl + tr) >> 1;
    build(2 * v + 1, tl, tm, tree, str);
    build(2 * v + 2, tm, tr, tree, str);
    tree[v] = union_nodes(tree[2 * v + 1], tree[2 * v + 2]);
    //print_node(tree[v]);
}

Node get(int v, int tl, int tr, int l, int r, Node* tree) {
    //cerr << tl << ' ' << tr << ' ' << l << ' ' << r << '\n';
    if (tr <= l || r <= tl) {
        //cerr << "!\n";
        return Node{0, 0, 0, 0, 0};
    }
    if (l <= tl && tr <= r) {
        //cerr << "!!\n";
        return tree[v];
    }
    int tm = (tl + tr) >> 1;
    Node res = union_nodes(get(2 * v + 1, tl, tm, l, r, tree), get(2 * v + 2, tm, tr, l, r, tree));

    //cerr << "!!!\n";
    //print_node(res);
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    cin >> s >> t;
    build(0, 0, s.size(), treeS, s);
    build(0, 0, t.size(), treeT, t);

    cin >> q;
    while (q--) {
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        l1--, l2--;

        Node v = get(0, 0, s.size(), l1, r1, treeS);
        Node u = get(0, 0, t.size(), l2, r2, treeT);

        //cerr << "\n\n";
        //print_node(v);
        //print_node(u);
        //cerr << '\n';

        if ((v.cntB + v.cntC) % 2 != (u.cntB + u.cntC) % 2) {
            cout << 0;
            continue;
        }
        if ((v.cntB + v.cntC) > (u.cntB + u.cntC)) {
            cout << 0;
            continue;
        }
        if (v.endA < u.endA) {
            cout << 0;
            continue;
        }
        if (v.endA == u.endA && v.cntB + v.cntC == 0 && u.cntB + u.cntC > 0) {
            cout << 0;
            continue;
        }
        if (v.endA % 3 == u.endA % 3) {
            cout << 1;
            continue;
        }
        if (v.endA > u.endA) {
            cout << (v.cntB + v.cntC < u.cntB + u.cntC ? 1 : 0);
            continue;
        }
    }

    #ifdef LOCAL
        cerr << "\n== " << 1.0 * clock() / CLOCKS_PER_SEC << " sec.\n";
    #endif
    return 0;
}

#include <cstdio>
#include <algorithm>
//
using namespace std;

char S[100005], T[100005];
int q;
int Ssum[100005], Tsum[100005];
int Ssuffix[100005], Tsuffix[100005];

int main()
{
    scanf("%s", S + 1);
    scanf("%s", T + 1);
    for (int i = 1; S[i]; i++) {
        Ssum[i] = Ssum[i-1];
        if (S[i] != 'A') {
            Ssum[i]++; Ssuffix[i] = 0;
        } else {
            Ssuffix[i] = Ssuffix[i-1] + 1;
        }
    }
    for (int i = 1; T[i]; i++) {
        Tsum[i] = Tsum[i-1];
        if (T[i] != 'A') {
            Tsum[i]++; Tsuffix[i] = 0;
        } else {
            Tsuffix[i] = Tsuffix[i-1] + 1;
        }
    }
    //for (int i = 1; T[i]; i++) printf("%d ", Tsum[i]);
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
        int l1, r1, l2, r2, a, b, x, y;
        scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
        a = Ssuffix[r1]; a = min(a, r1-l1+1);
        b = Tsuffix[r2]; b = min(b, r2-l2+1);
        x = Ssum[r1] - Ssum[l1-1];
        y = Tsum[r2] - Tsum[l2-1];
        //printf("%d %d %d %d\n", a, b, x, y);
        if (a < b) {
            printf("0");
        } else {
            if (a == b && x == 0 && y != 0) {
                printf("0"); continue;
            }
            if ((a-b) % 3 != 0) x += 2;
            printf("%d", y >= x && (y - x) % 2 == 0 ? 1 : 0);
        }
    }
    return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cassert>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)
typedef unsigned long long ULL;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=1e9+7;
const LL maxn=3e5+7;
const double eps=0.00000001;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a,T b){T ret=1;for (;b;b>>=1ll,a=1ll*a*a%M) if (b&1) ret=1ll*ret*a%M;return ret;}

int n,m;
int i,j,k;
char S[maxn],T[maxn];
int TA[maxn],TB[maxn],SA[maxn],SB[maxn];
char ans[maxn];
int check(int CA,int CB,int DA,int DB){
    if (CA<DA) return 0;
    if (CA==DA&&!CB&&DB) return 0;
    if ((CA-DA)%3) CB+=2;
    if (DB<CB) return 0;
    if ((DB-CB)&1) return 0;
    return 1;
}
int solve(int CA,int CB,int DA,int DB){
    int ret=check(CA,CB,DA,DB);
    printf("  %d %d %d %d; %d\n",CA,CB,DA,DB,ret);
    return ret;
}
int main(){
//    solve(2,1,0,3);
    scanf("%s%s",S+1,T+1);
    n=strlen(S+1);
    FOR(i,1,n){
        if (S[i]=='A') SA[i]=SA[i-1]+1,SB[i]=SB[i-1];
        else SB[i]=SB[i-1]+1;
    }n=strlen(T+1);
    FOR(i,1,n){
        if (T[i]=='A') TA[i]=TA[i-1]+1,TB[i]=TB[i-1];
        else TB[i]=TB[i-1]+1;
    }
    int C;
    scanf("%d",&C);
    REP(i,C){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int CA=min(SA[b],b-a+1),CB=SB[b]-SB[a-1];
        int DA=min(TA[d],d-c+1),DB=TB[d]-TB[c-1];
        ans[i]=check(CA,CB,DA,DB)+'0';
    }ans[C]=0;
    puts(ans);
}
/*
AABCCBAAB
ABCBCACC
7
1 3 1 2
2 2 2 4
7 9 1 1
3 4 2 3
4 5 1 3
1 1 5 7
1 1 6 7

CCBACACBCCCBBAAC
CACCAAABAACBBBBAC
20
7 7 2 15
3 11 14 15
4 9 6 12
10 15 13 17
10 16 5 14
14 15 12 16
16 16 16 16
3 15 9 14
10 12 8 12
15 15 9 10
14 15 8 15
7 14 17 17
15 15 17 17
15 15 5 9
4 14 12 17
13 15 8 12
1 4 2 2
6 13 17 17
11 14 5 11
15 16 2 9

*/

#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#define N 100001
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct rua
{
	char s[N];
	int n,a[N],b[N],x,y;
	void _()
	  {
	  int cnt=0;
	  for(int i=1;i<=n;i++)
	    if(s[i]=='A')a[i]=++cnt,b[i]=b[i-1];
	    else a[i]=cnt=0,b[i]=b[i-1]+1;
	  }
	void get(int l,int r)
	  {
	  x=b[r]-b[l-1];
	  if(!x)y=r-l+1;
	  else y=a[r];
	  }
}s,t;
int Q,a,b,c,d;
int main()
{
	scanf("%s",s.s+1),s.n=strlen(s.s+1);
	scanf("%s",t.s+1),t.n=strlen(t.s+1);
	s._(),t._();
	scanf("%d",&Q);
	while(Q--)
	  {
	  scanf("%d%d%d%d",&a,&b,&c,&d);
	  s.get(a,b),t.get(c,d);
	  if(!s.x && t.x)if(s.y>t.y)s.x+=2,s.y=t.y;else s.y--;
	  if(s.y<t.y){printf("0");continue;}
	  if((s.y-t.y)%3)s.x+=2;
	  if(s.x>t.x || (t.x-s.x)&1){printf("0");continue;}
	  printf("1");
	  }
	return printf("\n"),0;
}

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define eb emplace_back

#ifndef LOCAL
#define cerr if(0)cerr
#endif

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;

const int INF = 2 * int(1e9);
const ll INFll = 1ll * int(1e9) * int(1e9);
const int MOD = 1000000007;

template<typename T, typename Q>
ostream& operator<<(ostream& out, pair<T, Q>& a) {
    out << a.F << " " << a.S;
    return out;
}

template<typename T, typename Q>
istream& operator>>(istream& in, pair<T, Q>& a) {
    in >> a.F >> a.S;
    return in;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for (int i = 0; i < a.size(); ++i)
        in >> a[i];
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> a) {
    for (int i = 0; i < a.size(); ++i)
        if (i == a.size() - 1)
            out << a[i];
        else
            out << a[i] << " ";
    return out;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s;
    string t;
    cin >> s >> t;
    vi sum_s(s.size());
    vi sum_t(t.size());
    for (int i = 0; i < s.size(); ++i) {
        if (i)
            sum_s[i] += sum_s[i - 1];
        sum_s[i] += s[i] != 'A';
    }
    for (int i = 0; i < t.size(); ++i) {
        if (i)
            sum_t[i] += sum_t[i - 1];
        sum_t[i] += t[i] != 'A';
    }
    vi ls(s.size(), -1);
    vi lt(t.size(), -1);
    for (int i = 0; i < s.size(); ++i)
        if (s[i] != 'A')
            ls[i] = i;
        else if (i)
            ls[i] = ls[i - 1];
    for (int i = 0; i < t.size(); ++i)
        if (t[i] != 'A')
            lt[i] = i;
        else if (i)
            lt[i] = lt[i - 1];
    int m;
    cin >> m;
    while (m--) {
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        l1--, r1--, l2--, r2--;
        int ss = sum_s[r1];
        int st = sum_t[r2];
        if (l1)
            ss -= sum_s[l1 - 1];
        if (l2)
            st -= sum_t[l2 - 1];
        if (st == 0 && ss == 0) {
            if (r1 - l1 == r2 - l2 || r1 - l1 > r2 - l2 && (r1 - l1) % 3 == (r2 - l2) % 3)
                cout << 1;
            else
                cout << 0;
        } else if (ss > st || ss % 2 != st % 2) {
            cout << 0;
        } else {
            int ks = r1 - max(ls[r1], l1 - 1);
            int kt = r2 - max(lt[r2], l2 - 1);
            if (ss == 0)
                ks--;
            cerr << ss << " " << ks << " " << st << " " << kt << endl;
            if (ks == kt)
                cout << 1;
            else if (ks < kt)
                cout << 0;
            else if (ss == st && ks % 3 != kt % 3)
                cout << 0;
            else
                cout << 1;
        }
    }
    cerr << fixed << setprecision(0) << "TIME = " << clock() / (ld)CLOCKS_PER_SEC * 1000 << "\n";
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 2e5+7;
char S[maxn],T[maxn];
int Q,a,b,c,d;
int sumS[maxn],sumT[maxn];
int lastS[maxn],lastT[maxn];
int main(){
    scanf(" %s %s %d",S,T,&Q);
    for(int i = 0;S[i];++i){
        sumS[i+1] = sumS[i] + (S[i] == 'C' || S[i] == 'B');
        lastS[i+1] = lastS[i];
        if(S[i] == 'B' || S[i] == 'C')
            lastS[i+1] = i+1;
    }
    for(int i = 0;T[i];++i){
        sumT[i+1] = sumT[i] + (T[i] == 'C' || T[i] == 'B');
        lastT[i+1] = lastT[i];
        if(T[i] == 'B' || T[i] == 'C')
            lastT[i+1] = i+1;
    }
    while(Q--){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int delta = sumT[d]-sumS[b]+sumS[a-1]-sumT[c-1];
        int delta2 = b - max(a-1,lastS[b]) - (d - max(c-1,lastT[d]));
        if(delta < 0 || delta % 2 != 0 || delta2 < 0 || delta2 == 0 && !(sumS[b] - sumS[a-1]) && delta > 0) {
            putchar('0');
            continue;
        }
        if(delta2 == 0 || delta > 0 || delta2 % 3 == 0)
            putchar('1');
        else
            putchar('0');
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int maxn = 100500;

int sum1[maxn];
int sum2[maxn];
int cnt1[maxn];
int cnt2[maxn];

int main() {

    //freopen("input", "r", stdin);
    //freopen("output", "w", stdout);

	string s, t;
	cin >> s >> t;

	int n = s.size();
	int m = t.size();

	sum1[0] = 0;
	cnt1[0] = 0;
	for (int i = 1; i <= n; ++i) {
		if (s[i - 1] != 'A') {
			sum1[i] = sum1[i - 1] + 1;
			cnt1[i] = 0;
		} else {
			sum1[i] = sum1[i - 1];
			cnt1[i] = cnt1[i - 1] + 1;
		}
	}

	sum2[0] = 0;
	cnt2[0] = 0;
	for (int i = 1; i <= m; ++i) {
		if (t[i - 1] != 'A') {
			sum2[i] = sum2[i - 1] + 1;
			cnt2[i] = 0;
		} else {
			sum2[i] = sum2[i - 1];
			cnt2[i] = cnt2[i - 1] + 1;
		}
	}

	int q;
	cin >> q;
	for (int z = 0; z < q; ++z) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int a1, a2, x, y;
		x = sum1[b] - sum1[a - 1];
		y = sum2[d] - sum2[c - 1];
		a1 = min(cnt1[b], b - a + 1);
		a2 = min(cnt2[d], d - c + 1);

		if (x > y) {
			cout << 0;
			continue;
		}
		if (x == y) {
			if (a1 >= a2 && (a1 - a2) % 3 == 0) {
				cout << 1;
			} else {
				cout << 0;
			}
			continue;
		}
		if ((y - x) % 2 != 0) {
			cout << 0;
			continue;
		}
		if (a1 > a2) {
			cout << 1;
			continue;
		}
		if (a1 < a2) {
			cout << 0;
			continue;
		}
		if (x == 0) {
			cout << 0;
		} else {
			cout << 1;
		}
	}

    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
//#include<unordered_map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const int negINF = numeric_limits<int>::min();

const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;

void solve() {
    string s, t;
    cin >> s >> t;
    vector<int> bs(s.size() + 1, 0), bt(t.size() + 1, 0);
    vector<int> as(s.size() + 1, 0), at(t.size() + 1, 0);
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'C') {
            s[i] = 'B';
        }
        bs[i + 1] = bs[i] + (s[i] == 'B');
        if (s[i] == 'B')
            as[i + 1] = 0;
        else
            as[i + 1] = as[i] + 1;
    }
    for (int i = 0; i < t.size(); ++i) {
        if (t[i] == 'C') {
            t[i] = 'B';
        }
        bt[i + 1] = bt[i] + (t[i] == 'B');
        if (t[i] == 'B')
            at[i + 1] = 0;
        else
            at[i + 1] = at[i] + 1;
    }
    int q;
    cin >> q;
    string res = "";
    for (int qq = 0; qq < q; ++qq) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int b1 = bs[b] - bs[a - 1];
        int b2 = bt[d] - bt[c - 1];
        if (b1 > b2) {
            res += '0';
            continue;
        }
        if ((b2 - b1) & 1) {
            res += '0';
            continue;
        }
        int la1 = min(as[b], b - a + 1), la2 = min(at[d], d - c + 1);
        if (la1 < la2) {
            res += '0';
            continue;
        }
        if (b1 == 0) {
            if (b2 == 0) {
                if ((la1 - la2) % 3 == 0) {
                    res += '1';
                }
                else
                    res += '0';
                continue;
            }
            if (la1 == la2) {
                res += '0';
            }
            else
                res += '1';
            continue;
        }
        if ((la1 - la2) % 3 == 0) {
            res += '1';
            continue;
        }
        if (b1 == b2) {
            res += '0';
            continue;
        }
        res += '1';
    }
    cout << res << endl;
}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();

#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
int acc1[100005];
int acc2[100005];
int get1(int l, int r){
  int ret = acc1[r];
  if(l)ret -= acc1[l-1];
  return ret;
}
int get2(int l, int r){
  int ret = acc2[r];
  if(l)ret -= acc2[l-1];
  return ret;
}
int nxt1[100005], nxt2[100005];
int b41[100005], b42[100005];

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);
  string str1,str2;

  cin >> str1 >> str2;

  for(int i = 0; i < str1.size(); i++)if(str1[i]=='C')str1[i]='B';
  for(int i = 0; i < str2.size(); i++)if(str2[i]=='C')str2[i]='B';

  for(int i = str1.size()-1; i >= 0; i--){
    if(str1[i]=='A')
      nxt1[i] = nxt1[i+1] + 1;
  }
  for(int i = str2.size()-1; i >= 0; i--){
    if(str2[i]=='A')
      nxt2[i] = nxt2[i+1] + 1;
  }

  for(int i = 0; i < str1.size(); i++){
    if(str1[i] == 'A'){b41[i]++;
    if(i)b41[i] += b41[i-1];}
  }for(int i = 0; i < str2.size(); i++){
    if(str2[i] == 'A'){b42[i]++;
        if(i)b42[i] += b42[i-1];}
  }

  for(int i = 0; i < str1.size(); i++){
    if(i)acc1[i] = acc1[i-1];
    if(str1[i]=='B')acc1[i]++;

  }
  for(int i = 0; i < str2.size(); i++){
    if(i)acc2[i] = acc2[i-1];
    if(str2[i]=='B')acc2[i]++;

  }

  int q; cin >> q;

  while(q--){

    int l, r;
    cin >> l >> r;
    int a, b;
    cin >> a >> b;
    a--,b--;
    l--,r--;
    int x = get1(l,r);
    int y = get2(a,b);
    int tmp = b41[r];
    int tmp2 = b42[b];
    tmp = min(tmp,r-l+1);
    tmp2 = min(tmp2,b-a+1);
    if(tmp < tmp2){
      cout << 0;
      continue;
    }
    if(tmp > tmp2 && (tmp%3) != (tmp2%3)){
      x += 2;
    }
    if(tmp == tmp2 && x==0 && (y!=0)){
      cout << 0;
      continue;
    }
    if(x > y || ((y-x)&1))cout << 0;
    else cout << 1;

  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
const int maxn=100005;
const int maxm=(1<<25);
int n,m;
char s[maxn],t[maxn];
int bn1[maxn],bn2[maxn];
int an1[maxn],an2[maxn];
int a,b,c,d;
int main(){
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1),m=strlen(t+1);
    for(int i=1;i<=n;i++){
        bn1[i]+=bn1[i-1]+(s[i]!='A'?1:0);
        if(s[i]!='A')continue;
        an1[i]=1+an1[i-1];
    }
    for(int i=1;i<=m;i++){
        bn2[i]+=bn2[i-1]+(t[i]!='A'?1:0);
        if(t[i]!='A')continue;
        an2[i]=1+an2[i-1];
    }
    int Q;
    scanf("%d",&Q);
    while(Q--){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int b1num=bn1[b]-bn1[a-1];
        int a1num=min(b-a+1,an1[b]);
        int b2num=bn2[d]-bn2[c-1];
        int a2num=min(d-c+1,an2[d]);
        if(b1num>b2num){putchar('0');continue;}
        if(b1num==b2num){
            if(a1num<a2num){putchar('0');continue;}
            int cha=a1num-a2num;
            if(cha%3){putchar('0');}
            else putchar('1');
            continue;
        }
        if(b1num==0){
            if(b2num%2){putchar('0');continue;}
            if(a1num<=a2num){putchar('0');continue;}
            int lef=(a1num-a2num)%3;
            if(lef>b2num){putchar('0');continue;}
            putchar('1');
            continue;
        }
        if(b1num<b2num){
            int cha=b2num-b1num;
            if(cha%2){putchar('0');continue;}
            if(a1num<a2num){putchar('0');continue;}
            int lef=(a1num-a2num)%3;
            if(b1num+lef>b2num){putchar('0');continue;}
            putchar('1');
            continue;
        }
    }
    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

const int MX_SZ = 1e+5 + 42;

void process(vector<int> &a, vector<int> &b, string &s) {
    int carry = 0;
    for (int i = 1; i <= s.size(); ++i) {
        if (s[i - 1] == 'C') {
            s[i - 1] = 'B';
        }
        b[i] = b[i - 1] + (s[i - 1] == 'B');
        if (s[i - 1] == 'A') {
            ++carry;
        } else {
            carry = 0;
        }
        a[i] = carry;
    }
}

int get_a(int l, int r, vector<int> &pref, const string &s) {
    int ret = 0;
    if (pref[r] == pref[l] + (r - l)) {
        ret = pref[r] - pref[l];
        if (s[l - 1] == 'A') {
            ++ret;
        }
    } else {
        ret = pref[r];
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    vector<int> pref_sa(MX_SZ, 0), pref_sb(MX_SZ, 0);
    vector<int> pref_ta(MX_SZ, 0), pref_tb(MX_SZ, 0);
    process(pref_sa, pref_sb, s);
    process(pref_ta, pref_tb, t);
    int q;
    cin >> q;
    int ls, rs, lt, rt;
    int a_s, a_t;
    string ans = "";
    for (int i = 0; i < q; ++i) {
        //cout << ans << endl;
        cin >> ls >> rs >> lt >> rt;
        a_s = get_a(ls, rs, pref_sa, s);
        a_t = get_a(lt, rt, pref_ta, t);
        int b_s = pref_sb[rs] - pref_sb[ls - 1];
        int b_t = pref_tb[rt] - pref_tb[lt - 1];
        // cout << i << " " << a_s << " " << a_t << " " << b_s << " " << b_t << endl;
        if ((a_s == a_t) && ((b_s == 0) && (b_t != 0))) {
            ans+= '0';
            continue;
        }
        //cout << a_s << " " << a_t << endl;
        //cout << b_s << " " << b_t << endl;
        if (a_s < a_t) {
            ans += '0';
            continue;
        }
        if (a_s > a_t and (a_s % 3) != (a_t % 3)) {
            b_s += 2;
        }
        if (b_s <= b_t and (b_s % 2) == (b_t % 2)) {
            ans += '1';
            continue;
        } else {
            ans += '0';
            continue;
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

string s, t;
int as[maxn], bs[maxn], at[maxn], bt[maxn];

int main() {
//    fin("t.in");
    sync;
    cin >> s;
    cin >> t;
    clean(as); clean(bs); clean(at); clean(bt);
    F(i, 0, sz(s)) {
    	as[i] += (s[i] == 'A');
    	if (s[i] != 'A')
    		as[i] = 0;
    	bs[i] += (s[i] == 'B' || s[i] == 'C');
    	as[i + 1] = as[i];
    	bs[i + 1] = bs[i];
    }
    F(i, 0, sz(t)) {
    	at[i] += (t[i] == 'A');
    	if (t[i] != 'A')
    		at[i] = 0;
    	bt[i] += (t[i] == 'B' || t[i] == 'C');
    	at[i + 1] = at[i];
    	bt[i + 1] = bt[i];
    }

    string ans = "";
    int m;
    cin >> m;
    F(i, 0, m) {
    	int ls, rs, lt, rt;
    	cin >> ls >> rs >> lt >> rt; --ls; --rs; --lt; --rt;
    	int kas = min(as[rs], rs - ls + 1);
    	rs -= kas;
    	int kat = min(at[rt], rt - lt + 1);
    	rt -= kat;
    	int ss = (rs < 0 ? 0 : bs[rs]) - (ls == 0 ? 0 : bs[ls - 1]);
    	int st = (rt < 0 ? 0 : bt[rt]) - (lt == 0 ? 0 : bt[lt - 1]);
//    	cout << i << " " << ss << " " << st << " " << kas << " " << kat << " " << endl;
    	int ost = (kas - kat) % 3;
    	if (ss == 0) {
    		if (st == 0) {
    			if (kas >= kat && ost == 0)
    				ans += '1';
    			else
    				ans += '0';
    			cont;
    		}
    		ss += 2;
    		kas -= 1;
    		kas -= abs(kas - kat) % 3;
    		ost = (kas - kat) % 3;
    	}
    	if (ss <= st && ss % 2 == st % 2 && kas >= kat && (ost == 0 || (st - ss) >= 2))
    		ans += '1';
    	else
    		ans += '0';
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <cstdio>

using namespace std;

const int MAXN = 100010;
char s[MAXN], t[MAXN];
int cnts[MAXN], cntt[MAXN], coss[MAXN], cost[MAXN];

int main() {
	//freopen("in.txt", "r", stdin);
	scanf("%s%s", s+1, t+1);
	for(int i = 1; s[i]; i++) {
		cnts[i] = cnts[i-1]+(s[i]=='A');
		if(s[i] == 'A') coss[i] = coss[i-1]+1;
		else coss[i] = 0;
	}
	for(int i = 1; t[i]; i++) {
		cntt[i] = cntt[i-1]+(t[i]=='A');
		if(t[i] == 'A') cost[i] = cost[i-1]+1;
		else cost[i] = 0;
	}
	int q;
	scanf("%d", &q);
	int l1, r1, l2, r2;
	for(int i = 1; i <= q; i++) {
		scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
		int ln1 = r1-l1+1-cnts[r1]+cnts[l1-1];
		int ln2 = r2-l2+1-cntt[r2]+cntt[l2-1];
		int x = min(r1-l1+1, coss[r1]), y = min(r2-l2+1, cost[r2]);
		//printf("%d %d\n", x, y);
		if(x==r1-l1+1 && y<r2-l2+1) {
			if(x > y) x = y;
			else x--;
			ln1 += 2;
		}
		if(x < y) {
			printf("0"); continue;
		}
		if((x-y)%3 != 0) ln1 += 2;
		if(ln1<=ln2 && (ln1-ln2)%2==0) printf("1");
		else printf("0");
	}
	printf("\n");
}

#include<bits/stdc++.h>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	vector <int> prefs1(n + 1, 0), prefs2(n+ 1, 0), preft1(m + 1, 0), preft2(m + 1, 0);
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == 'A')
		{
			prefs1[i + 1] = prefs1[i] + 1;
			prefs2[i + 1] = prefs2[i];
		}
		else
		{
			prefs1[i + 1] = 0;
			prefs2[i + 1] = prefs2[i] + 1;
		}
	}
	for(int i = 0; i < m; i++)
	{
		if(t[i] == 'A')
		{
			preft1[i + 1] = preft1[i] + 1;
			preft2[i + 1] = preft2[i];
		}
		else
		{
			preft1[i + 1] = 0;
			preft2[i + 1] = preft2[i] + 1;
		}
	}
	int q;
	cin >> q;
	while(q--)
	{
		int l1, r1, l2, r2;
		cin >> l1 >> r1 >> l2 >> r2;
		l1--;
		r1--;
		l2--;
		r2--;
		int lens = min(r1 - l1 + 1, prefs1[r1 + 1]);
		int lent = min(r2 - l2 + 1, preft1[r2 + 1]);
		int cnts = prefs2[r1 + 1] - prefs2[l1];
		int cntt = preft2[r2 + 1] - preft2[l2];
		if(cnts % 2 != cntt % 2 || cnts > cntt || lent > lens)
		{
			cout << 0;
			continue;
		}
		if(cnts == cntt)
		{
			if(abs(lens - lent) % 3 == 0)
			{
				cout << 1;
			}
			else
			{
				cout << 0;
			}
		}
		else if(lens == lent)
		{
			if(cnts == 0)
			{
				cout << 0;
			}
			else
			{
				cout << 1;
			}
		}
		else
		{
		//	cout << "A";
			cout << 1;
		}
	}
    return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=110000;
char s[MAXN], t[MAXN];
int bs[MAXN], cs[MAXN];
int bt[MAXN], ct[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int m, n, q;
	scanf("%s%s", s+1, t+1);
	m=strlen(s+1), n=strlen(t+1);
	for (int i=1; i<=m; i++)
	{
		bs[i]=bs[i-1]+(s[i]!='A');
		cs[i]=s[i]=='A'?cs[i-1]+1:0;
	}
	for (int i=1; i<=n; i++)
	{
		bt[i]=bt[i-1]+(t[i]!='A');
		ct[i]=t[i]=='A'?ct[i-1]+1:0;
	}
	scanf("%d", &q);
	while (q--)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x=bs[b]-bs[a-1], y=bt[d]-bt[c-1];
		int z=min(cs[b], b-a+1), w=min(ct[d], d-c+1);
		if (x==y&&z>=w&&(z-w)%3==0
		  ||x<y&&(y-x)%2==0&&(x?z>=w:z>w)) putchar('1');
		else putchar('0');
	}
	putchar('\n');
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back

void calc(int *kol, int *as, string &s) {
	for (int i = 1; i <= s.size(); ++i) {
		kol[i] = kol[i - 1] + (s[i - 1] != 'A');
		if (s[i - 1] == 'A')
			as[i] = as[i - 1] + 1;
	}
	// for (int i = 1; i <= s.size(); ++i) {
	// 	cout << kol[i] << ' ';
	// }
	// cout << "\n";
	// for (int i = 1; i <= s.size(); ++i) {
	// 	cout << as[i] << ' ';
	// }
	// cout << "\n";
}

int get_kol(int *kol, int a, int b) {
	return kol[b] - kol[a - 1];
}

const int N = 1e+5 + 20;
int ks[N], as[N];
int kt[N], at[N];

int main() {
	// freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	string s, t;
	cin >> s >> t;
	calc(ks, as, s);
	calc(kt, at, t);
	int q;
	cin >> q;
	for (int i = 1; i <= q; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int tk = get_kol(kt, c, d);
		int sk = get_kol(ks, a, b);
		int ta = min(at[d], d - c + 1);
		int sa = min(as[b], b - a + 1);

		if (tk < sk || (tk - sk) % 2 == 1 || sa < ta) {
			cout << 0;
		} else if (sk == tk) {
			cout << ((sa - ta) % 3 == 0);
		} else {

			// cout << at[d] << ' ' << as[b] << "\n";
			// cout << "ta=" << ta << " sa=" << sa << "\n";
			if (sk == 0 && tk != 0) {
				sa--;
			}
			if (sa < ta) {
				cout << 0;
			} else {
				cout << 1;
			}
		}
	}
	return 0;

}

#pragma region Template
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <stack>
#include <set>
#include <algorithm>
#include <bitset>
#include <functional>
#include <ctime>
#include <cassert>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <complex>
#include <regex>
#include <numeric>
#include <typeinfo>
#include <type_traits>
#include <fstream>
#include <ctype.h>
#pragma comment(linker, "/STACK:167772160")

using namespace std;

#ifdef LOCAL

template <typename T, typename Q>
ostream& operator<<(ostream& os, pair<T, Q> p)
{
	return (os << '(' << p.first << ", " << p.second << ')');
}

int _iterable_indent = 0;
template<class T>
std::ostream& print_iterable(std::ostream& os, T beg, T end)
{
	if (_iterable_indent > 0)
		os << "\n";
	for (int i = 0; i < _iterable_indent; ++i)
		os << "\t";
	os << "[";
	for (auto it = beg; it != end; ++it)
	{
		if (it != beg)
			os << ", ";
		++_iterable_indent;
		os << *it;
		--_iterable_indent;
	}
	os << "]";
	return os;
}

template <class T >
std::ostream& operator << (std::ostream& os, const std::vector<T>& v)
{
	return print_iterable(os, v.begin(), v.end());
}
template <class T >
std::ostream& operator << (std::ostream& os, const std::set<T>& v)
{
	return print_iterable(os, v.begin(), v.end());
}
template <class T >
std::ostream& operator << (std::ostream& os, const std::multiset<T>& v)
{
	return print_iterable(os, v.begin(), v.end());
}
template <class T >
std::ostream& operator << (std::ostream& os, const std::unordered_set<T>& v)
{
	return print_iterable(os, v.begin(), v.end());
}
template <class T, class Q>
std::ostream& operator << (std::ostream& os, const std::map<T, Q>& v)
{
	return print_iterable(os, v.begin(), v.end());
}
template <class T, class Q>
std::ostream& operator << (std::ostream& os, const std::unordered_map<T, Q>& v)
{
	return print_iterable(os, v.begin(), v.end());
}

vector<string> _split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	auto arr_skip = false;
	while (getline(ss, x, c))
	{
		while (x[0] == ' ')
			x = x.substr(1);
		if (arr_skip)
		{
			for (auto h : x)
				if (h == ')')
					arr_skip = false;
			continue;
		}
		if (x.size() >= 3 && x.substr(0, 3) == "ARR")
		{
			arr_skip = true;
			v.emplace_back(x.substr(4));
		}
		else
			v.emplace_back(x);
	}
	return v;
}

void _print(vector<string>::iterator) {}
template<typename T, typename... Args>
void _print(vector<string>::iterator it, T a, Args... args) {
	string name = it->substr((*it)[0] == ' ', it->length());
	if (isalpha(name[0]))
		cerr << name << " = " << a << endl;
	else
		cerr << name << endl;
	_print(++it, args...);
}

template<class T>
auto _kekeke(T x)
{
	return x;
}

template<class T>
auto make_vector(T arr)
{
	return arr;
}

template<class T, class... Args>
auto make_vector(T arr, int len, Args... args)
{
	auto inside = make_vector(arr[0], args...);
	vector<decltype(_kekeke(inside))> v;
	for (int i = 0; i < len; ++i)
		v.push_back(make_vector(arr[i], args...));
	return v;
}

#define dbg(...) { _print(_split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); }
#define ARR(arr, ...) make_vector(arr, __VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define dbg(...) (void)0
#define ARR(arr, ...) (void)0
#define eprintf(...) (void)0
#endif
#define mp make_pair
#define rand govno_ebanoe
#define dbg_time() eprintf("\n\nTime: %.3lf\n", double(clock()) / CLOCKS_PER_SEC)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int INF = (int)1e9 + 10;
const ll LINF = ll(2e18) + 10;
const double PI = acosl(-1);
const double eps = 1e-8;
#pragma endregion

const int N = 2e5 + 10;
char a[N];
char b[N];
int n, m;
int psa[N], psb[N];
int befa[N], befb[N];
int q;

void solve()
{
	scanf("%s", a);
	n = strlen(a);
	scanf("%s", b);
	m = strlen(b);
	for (int i = 0; i < n; ++i)
	{
		psa[i + 1] = psa[i];
		if (a[i] != 'A')
			++psa[i + 1];
		else
		{
			if (i > 0)
				befa[i] = befa[i - 1];
			++befa[i];
		}
	}
	for (int i = 0; i < m; ++i)
	{
		psb[i + 1] = psb[i];
		if (b[i] != 'A')
			++psb[i + 1];
		else
		{
			if (i > 0)
				befb[i] = befb[i - 1];
			++befb[i];
		}
	}
	scanf("%d", &q);
	while (q--)
	{
		int l1, r1;
		int l2, r2;
		scanf("%d%d", &l1, &r1);
		scanf("%d%d", &l2, &r2);
		--l1, --r1;
		--l2, --r2;
		auto c1 = psa[r1 + 1] - psa[l1];
		auto c2 = psb[r2 + 1] - psb[l2];
		int sa = min(r1 - l1 + 1, befa[r1]);
		int sb = min(r2 - l2 + 1, befb[r2]);
		if (c1 <= c2 && (c1 + c2) % 2 == 0 && sa >= sb)
		{
			if (c1 == c2)
			{
				if (sa % 3 == sb % 3)
					printf("1");
				else
					printf("0");
			}
			else
			{
				if (sa == r1 - l1 + 1 && sa == sb)
					printf("0");
				else
					printf("1");
			}
		}
		else
			printf("0");
	}
	puts("");
}

#ifdef LOCAL
#define ERR_CATCH
//#define NOERR
#endif

int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#ifdef NOERR
	freopen("err.txt", "w", stderr);
#endif
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
#endif

#ifdef ERR_CATCH
	try
	{
#endif

#ifdef ST
		ios_base::sync_with_stdio(false);
		while (true)
			solve();
#endif

#ifdef CASES
#define MULTITEST
#endif

#ifdef MULTITEST
		int t;
		scanf("%d", &t);
		char endl1[5];
		fgets(endl1, 5, stdin);
		for (int i = 0; i < t; ++i)
		{
#ifdef CASES
			printf("Case #%d: ", i + 1);
#endif
			solve();
#ifdef CASES
			eprintf("Passed case #%d:\n", i + 1);
#endif
		}
#else
		solve();
#endif

#ifdef ERR_CATCH
	}
	catch (logic_error e)
	{
		dbg(e.what());
		puts("___________________________________________________________________________");
		exit(0);
	}
#endif
	dbg_time();
}

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=110000;
char s[MAXN], t[MAXN];
int bs[MAXN], cs[MAXN];
int bt[MAXN], ct[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int m, n, q;
	scanf("%s%s", s+1, t+1);
	m=strlen(s+1), n=strlen(t+1);
	for (int i=1; i<=m; i++)
	{
		bs[i]=bs[i-1]+(s[i]!='A');
		cs[i]=s[i]=='A'?cs[i-1]+1:0;
	}
	for (int i=1; i<=n; i++)
	{
		bt[i]=bt[i-1]+(t[i]!='A');
		ct[i]=t[i]=='A'?ct[i-1]+1:0;
	}
	scanf("%d", &q);
	while (q--)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x=bs[b]-bs[a-1], y=bt[d]-bt[c-1];
		int z=min(cs[b], b-a+1), w=min(ct[d], d-c+1);
		if (x==y&&z>=w&&(z-w)%3==0
		  ||x<y&&(y-x)%2==0&&(x?z>=w:z>w)) putchar('1');
		else putchar('0');
	}
	putchar('\n');
	return 0;
}//hello

#include<bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define dec(i, l, r) for (int i = l; i>=r;i--)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define pb(c) push_back(c)
#define vii vector<pair<int,int>>
#define ii pair<int,int>
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define pie 3.141592653589793238
#define inf ((ll)1e18)
#define eps 1e-14
#define mod ((int)1e9+7)
#define maxlg 18
const int maxn = ((int)2e5)+5;
#define left(i) ((i)<<1)
#define right(i) (((i)<<1)+1)
int as[maxn],at[maxn];
int bs[maxn],bt[maxn];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("input", "r", stdin);
#endif
    string s,t;
    cin>>s>>t;
    int A=0;
    rep (i,0,s.length()) {
        if (s[i]=='B' ||s[i]=='C') {
            bs[i+1]++;
            A=0;
        } else {
            A++;
        }
        as[i+1]=A;
        bs[i+1]+=bs[i];
    }
    A=0;
    rep (i,0,t.length()) {
        if (t[i]=='B' ||t[i]=='C') {
            bt[i+1]++;
            A=0;
        } else {
            A++;
        }
        at[i+1]=A;
        bt[i+1]+=bt[i];
    }
    int q;
    cin>>q;
    while (q--) {
        int ti,tj,si,sj;
        cin>>si>>sj>>ti>>tj;
        int bsrc = bs[sj]-bs[si-1];
        int btg = bt[tj]-bt[ti-1];
        int asrc = min(as[sj],sj-si+1);
        int atrgt = min(at[tj],tj-ti+1);

        if (btg<bsrc || ((btg%2)!=(bsrc%2))) {
            cout<<'0';
            continue;
        }
        if (bsrc==btg && atrgt<=asrc && ((atrgt%3)==(asrc%3))) {
            cout<<"1";
            continue;
        }
        if (bsrc==0 && btg>0 && atrgt<asrc  ) {
            cout<<"1";
            continue;
        }

        if (bsrc!=0 && btg>bsrc&& atrgt<=asrc  ) {
            cout<<"1";
            continue;
        }
        cout<<"0";

    }
     return 0;
}

#include <iostream>
using namespace std;
int pa[2][200000];
int pb[2][200000];
void calc(string a, int at){
	for(int i=0,cnt=0,cb=0;i<a.length();++i){
		cb+=a[i]!='A';
		if(a[i]=='A')++cnt;
		else cnt=0;
		pa[at][i+1]=cnt;
		pb[at][i+1]=cb;
	}
}
int main() {
	string sa,sb;
	cin>>sa>>sb;
	calc(sa,0);
	calc(sb,1);
	int q;
	cin>>q;
	while(q--){
		int a,b,x,y;
		cin>>a>>b>>x>>y;
		int nb0=pb[0][b]-pb[0][a-1];
		int na0=min(pa[0][b],b-a+1);
		int nb1=pb[1][y]-pb[1][x-1];
		int na1=min(pa[1][y],y-x+1);
		bool ans=true;
		if(!nb0&&nb1){
			na0=min(na0-1,na1);
			nb0+=2;
		}
		if(na0<na1||nb0%2!=nb1%2) ans=false;
		if(na0>=na1&&na0%3!=na1%3) nb0+=2;
		if(nb0>nb1) ans=false;
		cout<<(int)ans;
	}
}

#include <iostream>
using namespace std;
int la[1000002], lb[1000002], pa[1000002], pb[1000002], ka[1000002], kb[1000002];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    for (int i=1; i<=a.size(); i++)
    {
        if (a[i-1]!='A')
        {
            ka[i]++;
            la[i]=i;
        }
        else
            la[i]=la[i-1];
        pa[i]=pa[i-1]+ka[i];
    }
    for (int i=1; i<=b.size(); i++)
    {
        if (b[i-1]!='A')
        {
            kb[i]++;
            lb[i]=i;
        }
        else
            lb[i]=lb[i-1];
        pb[i]=pb[i-1]+kb[i];
    }
    int q;
    cin >> q;
    for (int i=0; i<q; i++)
    {
        int sa, ta, sb, tb;
        cin >> sa >> ta >> sb >> tb;
        int ila=pa[ta]-pa[sa-1], ilb=pb[tb]-pb[sb-1];
        int kona=ta-max(sa-1, la[ta]), konb=tb-max(sb-1, lb[tb]), n=0;
        //cout << ila << " " << ilb << " " << kona << " " << konb << "\n";
        if (ila==0 && ilb!=0)
        {
            ila=2;
            if (kona<=konb)
                n=1;
            kona=konb;
        }
        if (ila>ilb)
            n=1;
        if (ila%2!=ilb%2)
            n=1;
        if (konb>kona)
            n=1;
        if (konb%3!=kona%3 && ila==ilb)
            n=1;
        cout << (n^1);
    }
}

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

int Scnt[100005][3];
int Tcnt[100005][3];
int SlastnonA[100005];
int TlastnonA[100005];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin >> s >> t;
	Scnt[1][s.at(0)-'A']++;
	SlastnonA[1] = 0;
	Tcnt[1][t.at(0)-'A']++;
	TlastnonA[1] = 0;
	if(s.at(0) != 'A') {
		SlastnonA[1] = 1;
	}
	if(t.at(0) != 'A') {
		TlastnonA[1] = 1;
	}
	for(int i = 1; i < s.length(); i++) {
		Scnt[i+1][0] = Scnt[i][0];
		Scnt[i+1][1] = Scnt[i][1];
		Scnt[i+1][2] = Scnt[i][2];
		SlastnonA[i+1] = SlastnonA[i];
		Scnt[i+1][s.at(i)-'A']++;
		if(s.at(i) != 'A') {
			SlastnonA[i+1] = i+1;
		}
	}
	for(int i = 1; i < t.length(); i++) {
		Tcnt[i+1][0] = Tcnt[i][0];
		Tcnt[i+1][1] = Tcnt[i][1];
		Tcnt[i+1][2] = Tcnt[i][2];
		TlastnonA[i+1] = TlastnonA[i];
		Tcnt[i+1][t.at(i)-'A']++;
		if(t.at(i) != 'A') {
			TlastnonA[i+1] = i+1;
		}
	}
	int q;
	cin >> q;
	for(int i = 0; i < q; i++) {
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		int sum1 = Scnt[b][1]+Scnt[b][2]-Scnt[a-1][1]-Scnt[a-1][2];
		int sum2 = Tcnt[d][1]+Tcnt[d][2]-Tcnt[c-1][1]-Tcnt[c-1][2];
		//cout << sum1 << " " << sum2 << endl;
		if(sum1 <= sum2 && (sum2-sum1)%2 == 0) {
			if(sum2 == 0) {
				if(d-c <= b-a && (d-c)%3 == (b-a)%3) {
					cout << 1;
				} else {
					cout << 0;
				}
			} else {
				int lasts = max(a-1,SlastnonA[b]);
				int lastt = max(c-1,TlastnonA[d]);
				int cns = b-lasts;
				int cnt = d-lastt;
				if(cnt <= cns) {
					if(sum1 < sum2) {
						if(sum1 == 0) {
							if(cnt < cns) {
								cout << 1;
							} else {
								cout << 0;
							}
						} else {
							cout << 1;
						}
					} else {
						if(cnt%3 == cns%3) {
							cout << 1;
						} else {
							cout << 0;
						}
					}
				} else {
					cout << 0;
				}
			}
		} else {
			cout << 0;
		}
	}
	return 0;
}

#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

bool can(int sa, int sb, int ta, int tb) {
  if (sb > tb || sa < ta) return false;

  if ((sb == 0 && tb > 0) || (sa % 3 != ta % 3)) {
    if (sa == 0 || sa == ta) return false;
    sa = ta;
    sb += 2;
  }

  if (sb > tb) return false;

  return (tb - sb) % 2 == 0;
}

void calc(char* S, int* sa, int* sb) {
  int N = strlen(S);
  int ca = 0, cb = 0;
  REP(i, N) {
    if (S[i] == 'A') {
      ca++;
    } else {
      ca = 0;
      cb++;
    }
    sa[i] = ca;
    sb[i] = cb;
  }
}

const int MAX = 100100;

char S[MAX], T[MAX];
int sa[MAX], sb[MAX];
int ta[MAX], tb[MAX];

int main(void) {
  scanf("%s", S);
  scanf("%s", T);

  calc(S, sa, sb);
  calc(T, ta, tb);

  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    --a, --b, --c, --d;

    int v_sa = min(b - a + 1, sa[b]);
    int v_sb = sb[b] - (a == 0 ? 0 : sb[a - 1]);
    int v_ta = min(d - c + 1, ta[d]);
    int v_tb = tb[d] - (c == 0 ? 0 : tb[c - 1]);

    putchar(can(v_sa, v_sb, v_ta, v_tb) ? '1' : '0');
  }
  putchar('\n');
  return 0;
}

 #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=100005;
char s[maxn],t[maxn];
int sum1[maxn],sum2[maxn],n,m,l[maxn],l2[maxn];
int main(){
	scanf("%s",s+1);
	scanf("%s",t+1);
	n=strlen(s+1);m=strlen(t+1);
	rep(i,1,n)sum1[i]=sum1[i-1]+(s[i]=='B'||s[i]=='C');
	rep(i,1,m)sum2[i]=sum2[i-1]+(t[i]=='B'||t[i]=='C');
	rep(i,1,n){
		if(s[i]=='A')l[i]=l[i-1];else l[i]=i;
	}
	rep(i,1,m){
		if(t[i]=='A')l2[i]=l2[i-1];else l2[i]=i;
	}
	int q;read(q);
	while(q--){
		int a,b,c,d;read(a);read(b);read(c);read(d);
		int res1=sum1[b]-sum1[a-1],res2=sum2[d]-sum2[c-1];
		if((res1&1)!=(res2&1)){
			putchar('0');
			continue;
		}
		if(res1>res2){
			putchar('0');
			continue;
		}
		int v=(b-max(a-1,l[b]));
		int v2=(d-max(c-1,l2[d]));
		if(v<v2){
			putchar('0');
			continue;
		}
		if(res1<res2){
			if(v==v2&&(res1==0))
			putchar('0');
		else putchar('1');
			continue;
		}
		if(res1==res2){
			if(v%3!=v2%3){
				putchar('0');
			}else{
				putchar('1');
			}
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int nmax=1e5+42;
char inp[2][nmax];
pair<int/*A-s*/,int/*B-s*/> sum[2][nmax];

void get_inp(int id)
{
    string now;
    cin>>now;
    int SZ=now.size();
    for(int i=0;i<SZ;i++)
        {
        if(now[i]=='C')now[i]='B';
        inp[id][i+1]=now[i];
        }

    for(int i=1;i<=SZ;i++)
    {
        sum[id][i]=sum[id][i-1];
        if(inp[id][i]=='A')sum[id][i].first++;
        else sum[id][i].second++;
    }
}
pair<int/*A-s*/,int/*B-s*/> find_sum(int id,int l,int r)
{
    pair<int/*A-s*/,int/*B-s*/> ret=sum[id][r];
    ret.first=ret.first-sum[id][l-1].first;
    ret.second=ret.second-sum[id][l-1].second;
    return ret;
}
int a_ending(int id,int l,int r)
{
    int ok=r+1,not_ok=l-1;
    while(ok-not_ok>1)
    {
        int av=(ok+not_ok)/2;
        if(find_sum(id,av,r).second==0)ok=av;
        else not_ok=av;
    }
    return r-ok+1;
}
bool query()
{
    int l,r,lq,rq;

    cin>>l>>r>>lq>>rq;

    int bs=find_sum(0,l,r).second,bt=find_sum(1,lq,rq).second;

    int a_end_s=a_ending(0,l,r),a_end_t=a_ending(1,lq,rq);

    if(bs%2!=bt%2)return 0;
    if(bs>bt)return 0;

    if(bs==bt)return a_end_s>=a_end_t&&a_end_s%3==a_end_t%3;

    if(bs&&bs<bt)return a_end_s>=a_end_t;

    //bs=0, bt!=0
    return a_end_s>a_end_t;
}
int main()
{
get_inp(0);
get_inp(1);

int q;
cin>>q;
for(int i=1;i<=q;i++)
    cout<<query();
return 0;
}

/*
* C++11 code template for contests.
* @author: Andrei Kalendarov
* @e-mail: andreykalendarov@gmail.com
*/

//#define ANDREIKKAA_ALLOCATOR
const int _ML = 228;

const char _inpf[] =
#if defined(ANDREIKKAA)
        "input.txt"
#else
""
#endif
;
const char _outf[] =
#if defined(ANDREIKKAA)
        ""
#else
""
#endif
;

#if defined(ANDREIKKAA)
#undef NDEBUG
#else
#pragma GCC optimize("O3,no-stack-protector")
#endif
#include <bits/stdc++.h>
#if !defined(ANDREIKKAA)
#define endl '\n'
#endif
#define x first
#define y second
using namespace std;
#define rand abcdefghijklmnopqrstuvwxyz
#define random_shuffle abcdefghijklmnopqrstuvwxyz
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef double ld;
const ld PI = 3.14159265358979323846;
mt19937 rd(228);
#if defined(ANDREIKKAA_ALLOCATOR)
char _mem[_ML * 1024 * 1024];
size_t _ptr = 0;
inline void* operator new (size_t _x) { _ptr += _x; assert(_ptr < _ML * 1024 * 1024); return _mem + _ptr - _x; }
inline void operator delete (void*) { }
#endif
template<class T, class U> inline ostream &operator<< (ostream &, const pair<T, U> &);
template<class T, class U> inline istream &operator>> (istream &, pair<T, U> &);
template<class T> inline ostream &operator<< (ostream &, const vector<T> &);
template<class T> inline istream &operator>> (istream &, vector<T> &);
template<class T> inline ostream &operator<< (ostream &, const set<T> &);
template<class T> inline ostream &operator<< (ostream &, const multiset<T> &);
template<class T> inline ostream &operator<< (ostream &, const unordered_set<T> &);
template<class T> inline ostream &operator<< (ostream &, const unordered_multiset<T> &);
template<class T, class U> inline ostream &operator<< (ostream &, const map<T, U> &);
template<class T, class U> inline ostream &operator<< (ostream &, const unordered_map<T, U> &);

/* ________ CODE ________ */

void prec(string s, vector<int> &a, vector<int> &b)
{
    for(int i = 0; i < sz(s); ++i)
    {
        if(s[i] == 'B' || s[i] == 'C')
        {
            b[i] = 1;
        }
    }

    partial_sum(all(b), b.begin());

    for(int i = 0; i < sz(s); ++i)
    {
        if(i > 0)
        {
            a[i] = a[i - 1];
        }
        if(s[i] == 'A')
        {
            ++a[i];
        }
        else
        {
            a[i] = 0;
        }
    }
}

int get_t(vector<int> &v, int l, int r)
{
    return v[r] - (l == 0 ? 0 : v[l - 1]);
}

inline void _main_function()
{
    string s, t;
    cin >> s >> t;

    vector<int> sa(sz(s)), sb(sz(s)), ta(sz(t)), tb(sz(t));

    prec(s, sa, sb);
    prec(t, ta, tb);

    int n;
    cin >> n;

    for(int i = 0; i < n; ++i)
    {
        int sl, sr, tl, tr;
        cin >> sl >> sr >> tl >> tr;
        --sl;
        --sr;
        --tl;
        --tr;

        int ssb = get_t(sb, sl, sr);
        int ssa = min(sa[sr], sr - sl + 1);
        int ttb = get_t(tb, tl, tr);
        int tta = min(ta[tr], tr - tl + 1);

        if(ssa < tta) //ok
        {
            cout << 0;
            continue;
        }
        else if(ssb > ttb) //ok
        {
            cout << 0;
            continue;
        }
        else if((ttb - ssb) % 2 != 0) //ok
        {
            cout << 0;
            continue;
        }
        else if((ssa - tta) % 3 != 0 && ssb >= ttb)
        {
            cout << 0;
            continue;
        }
        else if(ssa == tta && ssb == 0 && ttb != 0)
        {
            cout << 0;
            continue;
        }
        else
        {
            cout << 1;
        }
    }
    cout << endl;
}

/* ________ CODE ________ */

int main()
{
#if defined(ANDREIKKAA)
    time_t _start = clock();
#endif
    if (_inpf[0] != '\0') assert(freopen(_inpf, "r", stdin) != nullptr);
    if (_outf[0] != '\0') assert(freopen(_outf, "w", stdout) != nullptr);
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cout << setprecision(20);
    //cout << fixed;

    _main_function();
#if defined(ANDREIKKAA)
    cout << "Time: " << (clock() - _start) / (ld)CLOCKS_PER_SEC << endl;
#endif
}

template<class T, class U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p)
{
    _out << _p.x << ' ' << _p.y;
    return _out;
}
template<class T, class U> inline istream &operator>> (istream &_in, pair<T, U> &_p)
{
    _in >> _p.x >> _p.y;
    return _in;
}
template<class T> inline ostream &operator<< (ostream &_out, const vector<T> &_v)
{
    if (_v.empty()) { return _out; }
    _out << *_v.begin();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T> inline istream &operator>> (istream &_in, vector<T> &_v)
{
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}
template<class T> inline ostream &operator<< (ostream &_out, const set<T> &_s)
{
    if (_s.empty()) { return _out; }
    _out << *_s.begin();
    for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s)
{
    if (_s.empty()) { return _out; }
    _out << *_s.begin();
    for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s)
{
    if (_s.empty()) { return _out; }
    _out << *_s.begin();
    for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s)
{
    if (_s.empty()) { return _out; }
    _out << *_s.begin();
    for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T, class U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m)
{
    if (_m.empty()) { return _out; }
    _out << '(' << _m.begin()->x << ": " << _m.begin()->y << ')';
    for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->x << ": " << _it->y << ')'; }
    return _out;
}
template<class T, class U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m)
{
    if (_m.empty()) { return _out; }
    _out << '(' << _m.begin()->x << ": " << _m.begin()->y << ')';
    for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->x << ": " << _it->y << ')'; }
    return _out;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;

const int maxn = 1E5 + 10;

int n, m, q, a[maxn], b[maxn], ma[maxn], mb[maxn];
char s[maxn], t[maxn];

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif

	scanf("%s", s + 1); n = strlen(s + 1);
	scanf("%s", t + 1); m = strlen(t + 1); cin >> q;
	for (int i = 1; i <= n; i++)
	{
		a[i] = a[i - 1] + (s[i] != 'A' ? 1 : 0);
		ma[i] = s[i] == 'A' ? ma[i - 1] + 1 : 0;
	}
	for (int i = 1; i <= m; i++)
	{
		b[i] = b[i - 1] + (t[i] != 'A' ? 1 : 0);
		mb[i] = t[i] == 'A' ? mb[i - 1] + 1 : 0;
	}
	while (q--)
	{
		int l1, r1, l2, r2;
		scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
		int x = a[r1] - a[l1 - 1];
		int y = b[r2] - b[l2 - 1];
		if (!x && !y)
		{
			x = r1 - l1 + 1; y = r2 - l2 + 1;
			if (x >= y && (x - y) % 3 == 0) putchar('1');
			else putchar('0');
		}
		else if (!x && y)
		{
			int cur = r1 - l1 + 1;
			if (cur - 1 >= mb[r2]) putchar((y & 1) ? '0' : '1');
			else putchar('0');
		}
		else
		{
			if ((x & 1) != (y & 1)) putchar('0');
			else if (mb[r2] > ma[r1]) putchar('0');
			else if (x > y) putchar('0');
			else if (x < y) putchar('1');
			else putchar((ma[r1] - mb[r2]) % 3 == 0 ? '1' : '0');
		}
	}
	return 0;
}

/*
 * Author       : YangDavid
 * Created Time : 2019年12月13日 星期五 11时19分45秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 102000;
char s[maxn], t[maxn];
int n, m, q, sufs[maxn], suft[maxn], pres[maxn], pret[maxn];

pii qryS(int l, int r) {
	int p = max(l - 1, r - sufs[r]);
	return {pres[p] - pres[l - 1], r - p};
}
pii qryT(int l, int r) {
	int p = max(l - 1, r - suft[r]);
	return {pret[p] - pret[l - 1], r - p};
}

int main() {
	scanf("%s%s%d", s + 1, t + 1, &q);
	n = strlen(s + 1);
	m = strlen(t + 1);
	rep(i, n) {
		if(s[i] == 'A') {
			sufs[i] = sufs[i - 1] + 1;
			pres[i] = pres[i - 1];
		} else {
			sufs[i] = 0;
			pres[i] = pres[i - 1] + 1;
		}
	}
	rep(i, m) {
		if(t[i] == 'A') {
			suft[i] = suft[i - 1] + 1;
			pret[i] = pret[i - 1];
		} else {
			suft[i] = 0;
			pret[i] = pret[i - 1] + 1;
		}
	}
	while(q--) {
		static int a, b, c, d, flag;
		flag = false;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		auto [sb, sa] = qryS(a, b);
	   	auto [tb, ta] = qryT(c, d);
		if(tb && sb == 0) sb += 2, sa--, flag = true;
		if(sa < ta) {
			putchar('0');
			continue;
		} else {
			if((sa - ta) % 3 != 0 && !flag) sb += 2;
			if(((sb^tb)&1)) putchar('0');
			else putchar(sb <= tb ? '1' : '0');
		}
	}

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int maxn = 1000011;

char S[maxn], T[maxn];
int Q, a, b, c, d;
int sumS[maxn], sumT[maxn];
int lastS[maxn], lastT[maxn];

int main() {
	cin >> S >> T >> Q;
	for (int i = 0; S[i]; ++i) {
		sumS[i + 1] = sumS[i] + (S[i] == 'C' || S[i] == 'B');
		lastS[i + 1] = lastS[i];
		if (S[i] == 'B' || S[i] == 'C')
			lastS[i + 1] = i + 1;
	}
	for (int i = 0; T[i]; ++i) {
		sumT[i + 1] = sumT[i] + (T[i] == 'C' || T[i] == 'B');
		lastT[i + 1] = lastT[i];
		if (T[i] == 'B' || T[i] == 'C')
			lastT[i + 1] = i + 1;
	}
	while (Q--) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int delta = sumT[d] - sumS[b] + sumS[a - 1] - sumT[c - 1];
		int delta2 = b - max(a - 1, lastS[b]) - (d - max(c - 1, lastT[d]));
		if (delta < 0 || delta % 2 != 0 || delta2 < 0 || delta2 == 0 && !(sumS[b] - sumS[a - 1]) && delta > 0) {
			putchar('0');
			continue;
		}
		if (delta2 == 0 || delta > 0 || delta2 % 3 == 0)
			putchar('1');
		else
			putchar('0');
	}

	//system("pause");
	return 0;
}

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

int main() {
#ifdef LOCAL_RUN
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#else
    cin.tie(NULL);
    iostream::sync_with_stdio(false);
#endif

    string s;
    cin >> s;
    string t;
    cin >> t;

    vector<int> stars, start;
    vector<int> as, at;
    stars.push_back(0);
    as.push_back(0);
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B' || s[i] == 'C') {
            stars.push_back(stars.back() + 1);
            as.push_back(0);
        } else {
            stars.push_back(stars.back());
            as.push_back(as.back() + 1);
        }
    }
    start.push_back(0);
    at.push_back(0);
    for (int i = 0; i < t.size(); ++i) {
        if (t[i] == 'B' || t[i] == 'C') {
            start.push_back(start.back() + 1);
            at.push_back(0);
        } else {
            start.push_back(start.back());
            at.push_back(at.back() + 1);
        }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int ls, rs, lt, rt;
        cin >> ls >> rs >> lt >> rt;

        int star_cnt_s = stars[rs] - stars[ls - 1];
        int star_cnt_t = start[rt] - start[lt - 1];
        int a_cnt_s = min(as[rs], rs - ls + 1);
        int a_cnt_t = min(at[rt], rt - lt + 1);
        if (star_cnt_t < star_cnt_s) {
            cout << '0';
            continue;
        }
        if (star_cnt_t % 2 != star_cnt_s % 2) {
            cout << '0';
            continue;
        }
        if (a_cnt_s < a_cnt_t) {
            cout << '0';
            continue;
        }

        if (star_cnt_s == star_cnt_t) {
            if (a_cnt_s % 3 == a_cnt_t % 3) {
                cout << '1';
            } else {
                cout << '0';
            }
        } else {
            if (star_cnt_s == 0) {
                if (a_cnt_s - 1 < a_cnt_t) {
                    cout << '0';
                } else {
                    cout << '1';
                }
            } else {
                cout << '1';
            }
        }
    }

#ifdef LOCAL_RUN
    cin.close();
    cout.close();
#endif
    return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
#define REP(i,n) for (int i=1;i<=n;++i)
#define FOR(i,n) for (__typeof(n.begin())i=n.begin();i!=n.end();++i)
using namespace std;

char s1[100010];
char s2[100010];
int n1,n2,m,l1,r1,l2,r2;
int a[100010];
int b[100010];
int c[100010];
int d[100010];

// BBBBBB1 AAAAA1
// BBB2 AAAAAAAAA2
bool check(int b1, int b2, int a1, int a2) {
	if (b1>b2) return false;
	if (b1==b2) return (a1>=a2 and (a1-a2)%3==0);
	if ((b2-b1)%2) return false;
	if (b1>0 && a1>=a2) return true;
	if (b1==0 && a1>a2) return true;
	return false;
}

int main() {
	scanf("%s",s1);
	scanf("%s",s2);
	n1=strlen(s1);
	n2=strlen(s2);
	// A=0 B=1
	REP(i,n1) a[i]=(s1[i-1]!='A');
	REP(i,n2) b[i]=(s2[i-1]!='A');
	REP(i,n1) if (a[i]==0) c[i]=c[i-1]+1;
	REP(i,n2) if (b[i]==0) d[i]=d[i-1]+1;
	REP(i,n1) a[i]+=a[i-1];
	REP(i,n2) b[i]+=b[i-1];
	scanf("%d",&m);
	REP(i,m) {
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		bool ans=check(a[r1]-a[l1-1],b[r2]-b[l2-1],min(c[r1],r1-l1+1),min(d[r2],r2-l2+1));
		printf(ans?"1":"0");
	}
	puts("");
	return 0;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define read(a) scanf("%d", &a)
#define readl(a) scanf("%lld", &a)
#define reads(a) scanf("%s", a)
#define readc(a) scanf("%c", &a)
#define debug(a, b) printf("%s = %d\n", a, b)
#define debug1(a, i, b) printf("%s[%d] = %d", a, i, b)
#define show(a) putchar(a)
#define pb push_back
#define _rand mt19937 RAND(time(0))
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
typedef long long LL;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 5e6 + 7;
char s[N], t[N];
int sumS[N], sumT[N], lastS[N], lastT[N];

signed main()
{
    Buff;
    int q, a, b, c, d;
    cin >> s >> t >> q;
    int n = strlen(s), m = strlen(t);
    for(int i = 0; i < n; i++)
    {
        sumS[i + 1] = sumS[i] + (s[i] == 'C' || s[i] == 'B');
        lastS[i + 1] = lastS[i];
        if(s[i] == 'B' || s[i] == 'C') lastS[i + 1] = i + 1;
    }
    for(int i = 0; i < m; i++)
    {
        sumT[i + 1] = sumT[i] + (t[i] == 'C' || t[i] == 'B');
        lastT[i + 1] = lastT[i];
        if(t[i] == 'B' || t[i] == 'C') lastT[i + 1] = i + 1;
    }
    while(q--)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x1 = sumT[d] - sumT[c - 1] - (sumS[b] - sumS[a - 1]);  // q - p
        int x2 = b - max(a - 1, lastS[b]) - (d - max(c - 1, lastT[d])); // n - m
        if(x1 < 0 || x1 & 1 || x2 < 0 || !x2 && !(sumS[b] - sumS[a - 1]) && x1 > 0) cout << '0';
        else if(!x2 || x1 > 0 || x2 % 3 == 0) cout << '1';
        else    cout << '0';
    }
    return 0;
}
/**
    Picking Strings
    2500
    思维/构造

设S区间中末尾A的数目为n T中为m
S中B的数目为p T中为q
1.如果n小于m 则一定不可能 因为不存在一种规则可以凭空生成A并移动到后面
2.如果n等于m
    2.1 如果p等于q 那可以
    2.2 如果p小于q 当且仅当q-p模2为0是可以 因为A可以在前端凭空产生 但只能分解成偶数个B
    2.3 如果p大于q 则不可以 因为B的数目是不可能减少的
3.如果n大于m
    3.1 如果p大于等于q 则不可以 因为减少A必然会产生B
    3.2 如果p小于q 则当且q-p模2为0时可以 因为可以分解后面的A来产生偶数个B
**/

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=100000+10;
template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}
int n,m,Q,i,l1,r1,l2,r2,cnt,sum1[N],sum2[N],a1[N],a2[N];
char s[N],t[N],ans[N];
int main(){
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1),m=strlen(t+1);
	for (i=1;i<=n;i++){
		sum1[i]=sum1[i-1]+(s[i]!='A');
		if (s[i]=='A') a1[i]=a1[i-1]+1;
		else a1[i]=0;
	}
	for (i=1;i<=m;i++){
		sum2[i]=sum2[i-1]+(t[i]!='A');
		if (t[i]=='A') a2[i]=a2[i-1]+1;
		else a2[i]=0;
	}
	for (read(Q);Q--;cnt++){
		read(l1),read(r1),read(l2),read(r2);
		int suffa1=min(a1[r1],r1-l1+1),suffa2=min(a2[r2],r2-l2+1);
		int cntb1=sum1[r1]-sum1[l1-1],cntb2=sum2[r2]-sum2[l2-1];
		if (suffa1<suffa2) ans[cnt]='0';
		else{
			if (!cntb1&&cntb2){
				if (suffa1==suffa2){
					ans[cnt]='0';
					continue;
				}
				else cntb1+=2;
			}
			else if ((suffa1-suffa2)%3) cntb1+=2;
			if (cntb1>cntb2||(cntb2-cntb1)&1) ans[cnt]='0';
			else ans[cnt]='1';
		}
		/*else if (suffa1==suffa2){
			if (cntb1>cntb2||((cntb2-cntb1)&1)) ans[cnt]='0';
			else ans[cnt]='1';
		}
		else{
			if ((suffa1-suffa2)%3) cntb1+=2;
			if (cntb1>cntb2||((cntb2-cntb1)&1)) ans[cnt]='0';
			else ans[cnt]='1';
		}*/
	}
	puts(ans);
	return 0;
}

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
inline long long readint(){
	long long a = 0; char c = getchar(), f = 1;
	for(; c<'0' or c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c and c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}
inline void writeint(long long x){
	if(x > 9) writeint(x/10);
	putchar((x%10)^48);
}
# define MB template < class T >
MB void getMax(T &a,const T &b){ if(a < b) a = b; }
MB void getMin(T &a,const T &b){ if(b < a) a = b; }

const int MaxN = 100005;
char s[MaxN], t[MaxN];
int cntS[MaxN], cntT[MaxN]; // D数量（前缀和）
int laS[MaxN], laT[MaxN]; // 末尾连续的A长度

int main(){
	// freopen("mine.txt","w",stdout);
	scanf("%s %s",s,t);
	int lens = strlen(s);
	for(int i=1; i<=lens; ++i){
		cntS[i] = cntS[i-1];
		if(s[i-1] == 'A')
			laS[i] = laS[i-1]+1;
		else laS[i] = 0, ++ cntS[i];
	}
	int lent = strlen(t);
	for(int i=1; i<=lent; ++i){
		cntT[i] = cntT[i-1];
		if(t[i-1] == 'A')
			laT[i] = laT[i-1]+1;
		else laT[i] = 0, ++ cntT[i];
	}
	int q = readint();
	while(q --){
		int ls = readint()-1, rs = readint();
		int lt = readint()-1, rt = readint(); // 左开右闭
		int cnts = cntS[rs]-cntS[ls], cntt = cntT[rt]-cntT[lt];
		int las = min(laS[rs],rs-ls), lat = min(laT[rt],rt-lt);
		if(cnts > cntt or (cnts-cntt)%2 != 0 or las < lat)
			putchar('0'); // 基本条件未达到
		else if(cnts == 0 and cntt != 0 and las == lat)
			putchar('0'); // 特殊情况：退无可退
		else if((las-lat)%3 == 0 or 2+cnts <= cntt)
			putchar('1'); // 在后面截一段lat
		else putchar('0');
	}
	putchar('\n');
	return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
typedef long long ll;
using namespace std;
string s;
string t;
vector <int> v[2];
vector <int> w[2];
int main() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) if (s[i] == 'C') s[i] = 'B';
	for (int i = 0; i < t.size(); i++) if (t[i] == 'C') t[i] = 'B';
	for (int i = 0; i < s.size(); i++) {
		v[s[i] - 'A'].pb(i);
	}
	for (int i = 0; i < t.size(); i++) {
		w[t[i] - 'A'].pb(i);
	}
	int q;
	cin >> q;
	for (int o = 0; o < q; o++) {
		int l, r, a, b;
		cin >> l >> r >> a >> b;
		l--;
		r--;
		a--;
		b--;
		int i = upper_bound(v[1].begin(), v[1].end(), r) - v[1].begin();
		i--;
		int colas;
		if (i == -1 || v[1][i] < l) colas = r - l + 1;
		else colas = r - v[1][i];
		int j = upper_bound(w[1].begin(), w[1].end(), b) - w[1].begin();
		j--;
		int colat;
		if (j == -1 || w[1][j] < a) colat = b - a + 1;
		else colat = b - w[1][j];
		int colbs = upper_bound(v[1].begin(), v[1].end(), r) - lower_bound(v[1].begin(), v[1].end(), l);
		int colbt = upper_bound(w[1].begin(), w[1].end(), b) - lower_bound(w[1].begin(), w[1].end(), a);
		if (colbs % 2 != colbt % 2) {
			cout << "0";
			continue;
		}
		if (colas < colat) {
			cout << "0";
			continue;
		}
		if (colbs > colbt) {
			cout << "0";
			continue;
		}
		if (colbs == 0) {
			if (colbt == 0) {
				if (colas % 3 == colat % 3) {
					cout << "1";
					continue;
				}
				else {
					cout << "0";
					continue;
				}
			}
			else {
				if (colas > colat) {
					cout << "1";
					continue;
				}
				else {
					cout << "0";
					continue;
				}
			}
		}
		if (colas % 3 == colat % 3) {
			cout << "1";
			continue;
		}
		if (colbs + 2 <= colbt) {
			cout << "1";
		}
		else cout << "0";
	}
	cout << endl;
    return 0;
}

// ~/BAU/ACM-ICPC/Teams/OverflowLimitExceeded/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 100005;
const ll MOD = 1e9 + 7;

char s[N], t[N];
int n, m, A1[N], B1[N], A2[N], B2[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	scanf("%s%s", s, t);
	n = strlen(s);
	m = strlen(t);

	for (int i = 1; i <= n; ++i) {
		A1[i] = s[i - 1] == 'A' ? A1[i - 1] + 1 : 0;
		B1[i] = B1[i - 1] + (s[i - 1] != 'A');
	}
	for (int i = 1; i <= m; ++i) {
		A2[i] = t[i - 1] == 'A' ? A2[i - 1] + 1 : 0;
		B2[i] = B2[i - 1] + (t[i - 1] != 'A');
	}

	int q, a, b, c, d;
	scanf("%d", &q);

	while (q--) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		if (int b1 = B1[b] - B1[a - 1], b2 = B2[d] - B2[c - 1], a1 = (b1 ? A1[b] : A1[b] - A1[a - 1]), a2 = (b2 ? A2[d] : A2[d] - A2[c - 1]);
		(!b1 && !b2 && a1>=a2 && a1%3==a2%3) ||
		(!b1 && b2 && b2%2==0 && a1 > a2) ||
		((b1 && b1 <= b2 && b1 % 2 == b2 % 2) &&
		((a1 >= a2 && a1 % 3 == a2 % 3) || (a1 > a2 && b1 < b2))))
			printf("1");
		else printf("0");
	}
	puts("");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

char solve(int numb1, int numa1, int numb2, int numa2){
    if(numb2 < numb1) return '0';
    if(numa1 < numa2) return '0';
    if((numb1 % 2) != (numb2 % 2)) return '0';
    if(numb1 == numb2){
        if(numa1 % 3 == numa2 % 3) return '1';
        return '0';
    }
    if(numb1 == 0 && numa1 == numa2) return '0';
    return '1';
}

string ans;
int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    string s[2];
    cin >> s[0] >> s[1];
    vector<int> bsums[2];
    bsums[0].push_back(0);
    bsums[1].push_back(0);
    vector<int> numa[2];
    for(int z = 0; z < 2; z++){
        int cur = 0;
        for(int i = 0; i < s[z].size(); i++){
            bsums[z].push_back(bsums[z][i] + (s[z][i] != 'A') );
            if(s[z][i] == 'A'){
                cur++;
            } else {
                cur = 0;
            }
            numa[z].push_back(cur);
        }
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--;
        int numb1 = bsums[0][b+1] - bsums[0][a];
        int numb2 = bsums[1][d+1] - bsums[1][c];
        int numa1 = min(b-a+1, numa[0][b]);
        int numa2 = min(d-c+1, numa[1][d]);
        ans += solve(numb1, numa1, numb2, numa2);
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define su(x) scanf("%u",&x)
#define sl(x) scanf("%ld",&x)
#define sli(x) scanf("%lld",&x)
#define slii(x,y) scanf("%lld %lld",&x,&y)
#define sliii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define slu(x) scanf("%llu",&x)
#define sf(x) scanf("%f",&x)
#define slf(x) scanf("%lf",&x)
#define slff(x,y) scanf("%lf %lf",&x,&y)
#define slfff(x,y,z) scanf("%lf %lf %lf",&x,&y,&z)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pf printf
#define fpf fprintf
#define pb push_back
#define f(i,x,y,z) for(int i=x;i<y;i=i+z)
#define f1(i,x,y,z) for(int i=x;i>y;i=i-z)
#define MAX 10000000
#define pi 2*acos(0)
#define mp make_pair
#define M 1000000007
#define xx first
#define yy second
#define N 5005
#define E 100005
#define vc vector
#define pq priority_queue
#define Q queue

using namespace std;

typedef long long int ll;
typedef unsigned long long int lu;

char s[E], t[E];

int o[2][E], b[2][E], p[2][E];

int main()
{
    int i, j, k, l, tmp, ii;
    ss(s);
    ss(t);
    ///pf("%s %s\n",s,t);
    for(i=1; s[i-1]!='\0'; i++)
    {
        if(s[i-1]=='A')
        {
            o[0][i] = o[0][i-1]+1;
            b[0][i] = b[0][i-1];
            p[0][i] = p[0][i-1];
        }
        else
        {
            p[0][i] = i;
            o[0][i] = o[0][i-1];
            b[0][i] = b[0][i-1]+1;
        }
        ///cout<<o[0][i]<<" "<<b[0][i]<<" "<<p[0][i]<<endl;
    }
    for(i=1; t[i-1]!='\0'; i++)
    {
        if(t[i-1]=='A')
        {
            o[1][i] = o[1][i-1]+1;
            b[1][i] = b[1][i-1];
            p[1][i] = p[1][i-1];
        }
        else
        {
            p[1][i] = i;
            o[1][i] = o[1][i-1];
            b[1][i] = b[1][i-1]+1;
        }
        ///cout<<o[1][i]<<" "<<b[1][i]<<" "<<p[1][i]<<endl;
    }

    int q;
    si(q);
    while(q--)
    {
        siii(i,j,k);
        si(l);
        if(b[0][j]-b[0][i-1]>b[1][l]-b[1][k-1] || (b[1][l]-b[1][k-1]-(b[0][j]-b[0][i-1]))%2==1)
        {
            pf("0");
            continue;
        }
        tmp = b[1][l]-b[1][k-1]-(b[0][j]-b[0][i-1]);
        ii = i;
        i = max(i-1,p[0][j]);
        k = max(k-1,p[1][l]);
        ///tmp -= (o[0][i]-o[0][ii-1]);
        ///if(tmp<0) tmp = 0;
        if(o[0][j]-o[0][i]<o[1][l]-o[1][k])
        {
            pf("0");
            continue;
        }
        else if(tmp==0 && (o[0][j]-o[0][i]-(o[1][l]-o[1][k]))%3!=0)
        {
            pf("0");
            continue;
        }
        else if(tmp>0 && o[0][j]-o[0][i]==o[1][l]-o[1][k] && b[0][j]-b[0][ii-1]==0)
        {
            pf("0");
            continue;
        }
        ///tmp -= (o[0][j]-o[0][ii-1]-(o[1][l]-o[1][k]));
        /*if(tmp>0){
            pf("0");
            continue;
        }*/
        pf("1");
    }
    return 0;
}

//                                               KEEP GRINDING
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define int long long
#define ld long double
#define MOD 1000000007
#define precise(i) fixed << setprecision(10) << i
#define f(i,a,b) for(int i=a;i<b;++i)

#define endl '\n'
#define debug cout<<"\n========================================\n";
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;

#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define PQ priority_queue
#define LB lower_bound
#define UB upper_bound
#define sz(x) (int)(x).size()
signed main(){
    fastio
    string s,t;
    cin>>s>>t;
    vector<int> bs,bt,nbs(s.size()),nbt(t.size());
    f(i,0,s.size()){
    	nbs[i]=(i>0 ? nbs[i-1] : (int)0);
    	if(s[i]!='A'){
    		bs.push_back(i);
    		nbs[i]++;
		}
	}
    f(i,0,t.size()){
    	nbt[i]=(i>0 ? nbt[i-1] : (int)0);
    	if(t[i]!='A'){
    		bt.push_back(i);
    		nbt[i]++;
		}
	}
	int q;	cin>>q;
	while(q--){
		int a,b,c,d;	cin>>a>>b>>c>>d;	a--,b--,c--,d--;
		int nbss=nbs[b]-(a>0 ? nbs[a-1] : (int)0);
		int nbst=nbt[d]-(c>0 ? nbt[c-1] : (int)0);
		if( nbst>=nbss and (nbst-nbss)%2==0 ){
		   int las,lat;
		   if( bs.size() ){
		      int i=UB(all(bs),b)-bs.begin()-1;
		      if( i == -1 ){
		         las=b-a+1;
		      }else{
		         las=min(b-(bs[i]),b-a+1);
		      }
		   }else{
		      las=b-a+1;
		   }
			if( bt.size() ){
		      int i=UB(all(bt),d)-bt.begin()-1;
		      if( i == -1 ){
		         lat=d-c+1;
		      }else{
		         lat=min(d-c+1,d-(bt[i]));
		      }
		   }else{
		      lat=d-c+1;
		   }
		   if( nbss == 0 and nbst>0 ){
		      las--;
		   }
			if( (las>=lat and (las-lat)%3==0) ){
				cout<<1;
			}else if(las>=lat and nbst>nbss){
				cout<<1;
			}else{
			   cout<<0;
			}
		}else{
			cout<<0;
		}
	}
}

#define FNAME ""

#undef __STRICT_ANSI__

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define fst first
#define snd second
#define sz(x) (int)((x).size())
#define forn(i,n) for (int i = 0; (i) < (n); ++i)
#define fornr(i,n) for (int i = (int)(n) - 1; (i) >= 0; --i)
#define forab(i,a,b) for (int i = (a); (i) < (b); ++i)
#define forba(i,a,b) for (int i = (int)(b) - 1; (i) >= (a); --i)
#define forit(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(),(c).end()

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) static_cast<void>(0)
#endif

#ifdef _WIN32
	#define I64 "%I64d"
	#define U64 "%I64u"
#else
	#define I64 "%lld"
	#define U64 "%llu"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef unsigned int uint;
typedef vector <int> vi;
typedef pair <int, int> pii;

const int N = 1e5 + 100;

int sumS[N], sumT[N];
int cntS[N], cntT[N];

bool ok(int numS, int numT, int cntSS, int cntTT) {
	 return ((numS % 2 == numT % 2) && (numS <= numT) && (cntSS >= cntTT) && (cntSS % 3 == cntTT % 3));
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	int n = sz(s);
	int m = sz(t);
	forn(i, n) {
		sumS[i + 1] = sumS[i];
		cntS[i + 1] = cntS[i] + 1;
		if (s[i] != 'A') sumS[i + 1]++, cntS[i + 1] = 0;
	}
	forn(i, m) {
		sumT[i + 1] = sumT[i];
		cntT[i + 1] = cntT[i] + 1;
		if (t[i] != 'A') sumT[i + 1]++, cntT[i + 1] = 0;
	}
	int q;
	cin >> q;
	forn(i, q) {
		int ls, rs, lt, rt;
		cin >> ls >> rs >> lt >> rt;
		int numS = (sumS[rs] - sumS[ls - 1]);
		int numT = (sumT[rt] - sumT[lt - 1]);
		int cntSS = min(cntS[rs], rs - ls + 1);
		int cntTT = min(cntT[rt], rt - lt + 1);
		bool can = false;
		if (numS != 0 || numT == 0)
			can |= ok(numS, numT, cntSS, cntTT);
		if (cntSS >= 1)
			can |= ok(numS + 2, numT, cntSS - 1, cntTT);
		if (cntSS >= 2)
			can |= ok(numS + 2, numT, cntSS - 2, cntTT);
		if (cntSS >= 3)
			can |= ok(numS + 2, numT, cntSS - 3, cntTT);
		if (can) {
			cout << 1;
		} else {
			cout << 0;
		}
	}
	cout << '\n';
	return 0;
}

// FAILS on A, BBA.

#include <bits/stdc++.h>
using namespace std;

vector<char> s(1, ' '), t(1, ' ');
int q;
vector<int> a, b, c, d;

void Load() {
  char in[100001];
  scanf("%s", in);
  for (int i = 0; in[i] != '\0'; ++i) s.push_back(in[i]);
  scanf("%s", in);
  for (int i = 0; in[i] != '\0'; ++i) t.push_back(in[i]);
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int ia, ib, ic, id;
    scanf("%d %d %d %d", &ia, &ib, &ic, &id);
    a.push_back(ia);
    b.push_back(ib);
    c.push_back(ic);
    d.push_back(id);
  }
}

// Smallest index in [a, b] such that pref[index] == pref[b].
int BinSearch(int a, int b, const vector<int>& pref) {
  int lo = a, hi = b;  // hi = highest one that works
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (pref[mid] == pref[b])
      hi = mid;
    else
      lo = mid + 1;
  }
  return hi;
}

void Solve() {
  vector<int> spref(1, 0), tpref(1, 0);
  int cnt = 0;
  for (int i = 1; i <= s.size(); ++i) {
    if (s[i] != 'A') cnt++;
    spref.push_back(cnt);
  }
  cnt = 0;
  for (int i = 1; i <= t.size(); ++i) {
    if (t[i] != 'A') cnt++;
    tpref.push_back(cnt);
  }

  for (int i = 0; i < q; ++i) {
    const int bc_ins = spref[b[i]] - spref[a[i] - 1];
    const int bc_int = tpref[d[i]] - tpref[c[i] - 1];
    const int bc_to_add = bc_int - bc_ins;
    const int s_lastbci = spref[b[i]] == spref[a[i] - 1]
                              ? a[i] - 1
                              : BinSearch(a[i], b[i], spref);
    const int t_lastbci = tpref[d[i]] == tpref[c[i] - 1]
                              ? c[i] - 1
                              : BinSearch(c[i], d[i], tpref);
    const int adiff = b[i] - s_lastbci - (d[i] - t_lastbci);
    bool cando = false;
    if (bc_to_add > 0) {
      cando = bc_to_add % 2 == 0 && adiff >= 0;
      // If I HAVE to use an ending A to generate B's and C's...
      if (adiff == 0 && s_lastbci == a[i] - 1) cando = false;
    } else if (bc_to_add == 0)
      cando = adiff >= 0 && adiff % 3 == 0;
    if (cando)
      printf("1");
    else
      printf("0");
  }
  puts("");
}

int main() {
  Load();
  Solve();
  return 0;
}

#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int S[MAX_N];
int T[MAX_N];
int AS[MAX_N], AT[MAX_N];
string ss, st;
int Q;

void solve() {
	string str;
	cin >> str;
	ss = str;
	rep(i, 0, sz(str)) {
		S[i + 1] += S[i];
		if(str[i] != 'A') {
			S[i + 1]++;
		}
		else AS[i + 1] = AS[i] + 1;
	}
	cin >> str;
	st = str;
	rep(i, 0, sz(str)) {
		T[i + 1] += T[i];
		if(str[i] != 'A') {
			T[i + 1]++;
		}
		else AT[i + 1] = AT[i] + 1;
	}
	// rer(i, sz(ss), 0) {
	// 	if(ss[i] == 'A') {
	// 		AS[i] = AS[i + 1] + 1;
	// 	}
	// }
	// rer(i, sz(st), 0) {
	// 	if(st[i] == 'A') {
	// 		AT[i] = AT[i + 1] + 1;
	// 	}
	// }
	// debug(vi(AS, AS + sz(ss) + 1));
	cin >> Q;
	string ans;
	while(Q--) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		a--; c--;
		int e = S[b] - S[a], f = T[d] - T[c];
		// debug(a, c, d, e, f);
		if(e <= f && e % 2 == f % 2) {
			int g = min(AS[b], b - a), h = min(AT[d], d - c);
			if(e == f) {
				if(g >= h && g % 3 == h % 3) {
					ans += '1';
				}
				else ans += '0';
			}
			else if(e != 0) {
				if(g >= h) ans += '1';
				else ans += '0';
			}
			else {
				if(g > h) ans += '1';
				else ans += '0';
			}
		}
		else ans += '0';
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <memory.h>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
const double pi = 3.1415926535897932384626433832795;
const double eps = 1e-12;
const int INF = 1<<30;
const LL LINF = 1ll<<60;

#define pb push_back
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define CLR(a, v) memset((a),(v),sizeof(a))
#define sqr(a) ((a)*(a))
const int BUFFER_SZ = 1 << 20;
const int MOD = 1000*1000*1000+7;

char BUFFER[BUFFER_SZ];
int gi() { int x; scanf("%d", &x); return x; }
LL gll() { LL x; scanf("%lld", &x); return x; }
VI gvi(int n) { VI a; while(n-->0) a.pb(gi()); return a;}
string gs() { scanf("%s", BUFFER); return string(BUFFER); }
template <class T> void print(vector<T> &x, string format) { format += "%c";for (int i = 0; i < x.size(); ++i) printf(format.c_str(), x[i], i+1==x.size() ? '\n' : ' '); }
// ---------------------------------------------------------- //

struct strun {
  VI rightA;
  VI SUMnotA;
  strun(string s) {
    int sum = 0;
    int a = 0;
    for (int i = 0; i < s.size(); ++i) {
      sum += s[i]!='A'?1:0;
      SUMnotA.pb(sum);
      if (s[i]!='A') a = 0;
      else ++a;
      rightA.pb(a);
    }
  }

  int getA(int l, int r) {
    return min(r-l+1, rightA[r]);
  }
  int getNA(int l, int r) {
    return SUMnotA[r] - (l>0?SUMnotA[l-1]:0);
  }
};

set<string> S;
void dfs(string s) {
  if (s.size()>10) return;
  if (S.count(s)) return;
  S.insert(s);
  for (int i = 0; i < (int)s.size()-3+1; ++i) {
    if (s[i]=='A' && s[i+1]=='A' && s[i+2]=='A') {
      dfs(s.substr(0,i) + s.substr(i+3));
    }
  }
  for (int i = 0; i < s.size(); ++i) {
    if (s[i]=='A') dfs(s.substr(0,i) + "BC" + s.substr(i+1));
    if (s[i]=='B') dfs(s.substr(0,i) + "AC" + s.substr(i+1));
    if (s[i]=='C') dfs(s.substr(0,i) + "AB" + s.substr(i+1));
  }
}

void solve() {
  string s = gs();
  string t = gs();

  strun S(s);
  strun T(t);

  int n = gi();
  for (int i = 0; i < n; ++i) {
    int a = gi()-1;
    int b = gi()-1;

    int c = gi()-1;
    int d = gi()-1;

    int a1 = S.getA(a,b);
    int a2 = T.getA(c,d);

    int b1 = S.getNA(a,b);
    int b2 = T.getNA(c,d);
    if (b1%2!=b2%2 || b1>b2) printf("0");
    else if (b1==b2) {
      if (a1<a2 || a1%3 != a2%3) printf("0");
      else printf("1");
    } else {
      if (a1<a2) printf("0");
      else if (a1==a2 && b1==0 && b2!=0) printf("0");
      else if (a1%3!=a2%3 && b1+2>b2) printf("0");
      else printf("1");
    }
  }
  printf("\n");
}

int main() {
#ifdef DEAD_RABBIT
  freopen("../in.txt","r",stdin);
  //freopen("../out.txt","w",stdout);
  clock_t start = clock();
#endif
  /*
  S.clear();
  dfs("AA");
  for (string s : S) {
    if (s.size()<=3)
      printf("%s\n", s.c_str());
  }//*/

  solve();
#ifdef DEAD_RABBIT
  fprintf(stdout, "Time: %.3lf\n", 1.0*(clock()-start)/CLOCKS_PER_SEC);
#endif
  return 0;
}

#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mod 1000000007
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=10000000000000000;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
int  max3(int  a,int  b, int  c)
{
    return max(c,max(a,b));
}
int  min3(int  a,int  b,int  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y )
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);//%mod;
        y = y>>1;
        x = (x*x);//%mod;
    }
    return res;
}
int  logg(int  a)
{
    int  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
int  gcd(int  a,int   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int abso(int x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
int main()
{
    fastio;
    string s,t;
    cin>>s>>t;
    int q;
    cin>>q;
    vvi A(s.size());
    vvi B(t.size());
    for(int i=0;i<s.size();i++)
    {
        A[i].resize(3);
    }
    for(int i=0;i<t.size();i++)
    {
        B[i].resize(3);
    }
    for(int i=0;i<s.size();i++)
    {
        if(i==0)
        {
            A[i][s[i]-'A']=1;
        }
        else
        {
            A[i]=A[i-1];
            A[i][s[i]-'A']=A[i-1][s[i]-'A']+1;
        }
    }
    vi lenA(s.size());vi lenB(t.size());
    for(int i=0;i<s.size();i++)
    {
        if(i==0)
        {
            if(s[i]=='A')
            {
                lenA[0]=1;
            }
            else
            {
                lenA[0]=0;
            }
        }
        else
        {
            if(s[i]=='A')
            {
                lenA[i]=1+lenA[i-1];
            }
            else
            {
                lenA[i]=0;
            }
        }
    }
    for(int i=0;i<t.size();i++)
    {
        if(i==0)
        {
            if(t[i]=='A')
            {
                lenB[0]=1;
            }
            else
            {
                lenB[0]=0;
            }
        }
        else
        {
            if(t[i]=='A')
            {
                lenB[i]=1+lenB[i-1];
            }
            else
            {
                lenB[i]=0;
            }
        }
    }
    for(int i=0;i<t.size();i++)
    {

        if(i==0)
        {
            B[i][t[i]-'A']=1;

        }
        else
        {
            B[i]=B[i-1];
            B[i][t[i]-'A']=B[i-1][t[i]-'A']+1;
        }
    }
    while(q--)
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;a--;b--;c--;d--;
        int num1=A[b][1]+A[b][2];
        if(a>0)
        {
            num1-=(A[a-1][1]+A[a-1][2]);
        }
        int num2=B[d][1]+B[d][2];//-B[c-1][1]-B[c-1][2];
        if(c>0)
        {
            num2-=(B[c-1][1]+B[c-1][2]);
        }
        if(min(lenA[b],b-a+1)>=min(lenB[d],d-c+1))
        {
            if((min(lenA[b],b-a+1)-min(lenB[d],d-c+1))==0&&(num1==0&&num2!=0))
            {
                cout<<"0";continue;
            }
            if(((min(lenA[b],b-a+1)-min(lenB[d],d-c+1))%3==0))
            {
                if((num1<=num2)&&(num1%2==num2%2))
                {
                    cout<<"1";
                }
                else
                {
                    cout<<"0";
                }
            }
            else
            {
                if(((num1+2)<=(num2))&&(num2%2==num1%2))
                {
                    cout<<"1";
                }
                else
                {
                    cout<<"0";
                }
            }
        }
        else
        {
            cout<<"0";
        }
    }
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,char middle=' '){
    for(int i=0;i<vec_s.size();i++)printf("%d%c",vec_s[i],(i!=vec_s.size()-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,char middle=' '){
    for(int i=0;i<vec_s.size();i++)printf("%lld%c",vec_s[i],(i!=vec_s.size()-1?middle:'\n'));
}

int bc[2][100005];
int fa[2][100005];

string sa;
bool s[100005];

int main(){
    int n,m;
    int i,j,k;
    int a,b,c,d;
    int p,q,r;
    for(i=0;i<2;i++){
        cin>>sa;
        for(j=0;j<sa.size();j++){
            bc[i][j+1]=bc[i][j];
            if(sa[j]!='A')bc[i][j+1]++;
        }
        for(j=0;j<sa.size();j++){
            if(sa[j]=='A')fa[i][j+1]=fa[i][j]+1;
        }
    }
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b>>c>>d;
        p=(bc[1][d]-bc[1][c-1])-(bc[0][b]-bc[0][a-1]);
        if(p<0 || p%2!=0){
            s[i]=false;
            continue;
        }
        q=min(fa[0][b],b-a+1)-min(fa[1][d],d-c+1);
        if(fa[0][b]>=b-a+1){
            if(p==0 && q>=0 && q%3==0)s[i]=true;
            else if(p>0 && q>=1)s[i]=true;
            else s[i]=false;
        }else{
            if(p==0 && q>=0 && q%3==0)s[i]=true;
            else if(p>0 && q>=0)s[i]=true;
            else s[i]=false;
        }
    }
    for(i=0;i<n;i++){
        if(s[i])cout<<1;
        else cout<<0;
    }
    cout<<endl;
}

#include<bits/stdc++.h>
using namespace std;
const int mxn = 100005;

int pbc[mxn] , sbc[mxn] , sac[mxn], pac[mxn];
string src , pp;

void give_a_fuck_to_source()
{
	sbc[0] = src[0]!='A';
	sac[0] = src[0]=='A';
	for(int i = 1; i < src.size(); i++)
	{
		sbc[i] = sbc[i-1] + (src[i]!='A');
		sac[i] = src[i]=='A' ? sac[i-1] + 1 : 0;
	}
	/*for(int i = 0; i < src.size(); i++)
	{
		cout<<sbc[i]<<" ";
	}
	cout<<endl;
	for(int i = 0; i < src.size(); i++)
	{
		cout<<sac[i]<<" ";
	}
	cout<<endl;*/
}

void give_a_fuck_to_pattern()
{
	pbc[0] = pp[0]!='A';
	pac[0] = pp[0]=='A';
	for(int i = 1; i < pp.size(); i++)
	{
		pbc[i] = pbc[i-1] + (pp[i]!='A');
		pac[i] = pp[i]=='A' ? pac[i-1] + 1 : 0;
	}
	/*for(int i = 0; i < pp.size(); i++)
	{
		cout<<pbc[i]<<" ";
	}
	cout<<endl;
	for(int i = 0; i < pp.size(); i++)
	{
		cout<<pac[i]<<" ";
	}
	cout<<endl;*/
}

int get_sbc(int to , int from)
{
	if(from==0) return sbc[to];
	return sbc[to] - sbc[from-1];
}

int get_pbc(int to , int from)
{
	if(from==0) return pbc[to];
	return pbc[to] - pbc[from-1];
}

int get_sac(int to , int from)
{
	return min(sac[to] , to - from+1);
}

int get_pac(int to , int from)
{
	return min(pac[to] , to-from+1);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	//string s;
	cin>>src>>pp;
	give_a_fuck_to_pattern();
	give_a_fuck_to_source();

	int n;
	cin>>n;
	int si , sj , pi, pj;
	for(int i = 0; i < n;i++)
	{
		cin>>si>>sj>>pi>>pj;
		si-=1;
		sj-=1;
		pi-=1;
		pj-=1;

		int gotsbc = get_sbc(sj ,si);
		int gotsac = get_sac(sj , si);
		int gotpbc = get_pbc(pj , pi);
		int gotpac = get_pac(pj , pi);
		//cout<<gotsbc<<" sds "<<gotsac<<" mmm "<<gotpbc<<" sds "<<gotsac<<endl;
		if(gotsbc > gotpbc)
			cout<<0;
		else if(gotsbc == gotpbc)
		{
			cout<< ((gotsac >= gotpac) && (gotsac - gotpac)%3==0) ;
		}
		else if(gotsbc==0)
		{
			cout<< (gotpbc %2==0 && gotsac > gotpac) ;
		}
		else
		{
			cout<<((gotpbc - gotsbc)%2==0 && gotsac >= gotpac);
		}

	}
	cout<<endl;

	return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 101000;
const int INF = 1000000007;
const double PI = acos(-1.0);

int cntP[MAXN], cntQ[MAXN];
int preP[MAXN], preQ[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    string P, Q;
    cin >> P >> Q;
    for (int i = 0; i < P.size(); ++i) {
        preP[i + 1] = preP[i];
        cntP[i + 1] = cntP[i];
        if (P[i] == 'A') continue;
        cntP[i + 1] = cntP[i] + 1;
        preP[i + 1] = i + 1;
    }
    for (int i = 0; i < Q.size(); ++i) {
        preQ[i + 1] = preQ[i];
        cntQ[i + 1] = cntQ[i];
        if (Q[i] == 'A') continue;
        cntQ[i + 1] = cntQ[i] + 1;
        preQ[i + 1] = i + 1;
    }

    int M;
    cin >> M;
    for (int i = 0; i < M; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int A = cntP[b] - cntP[a - 1];
        int B = cntQ[d] - cntQ[c - 1];
        if ((A + B) & 1) {
            cout << 0;
            continue;
        }
        if (A > B) {
            cout << 0;
            continue;
        }
        int B1 = preP[b], B2 = preQ[d];
        if (A == B) {
            if (A == 0) {
                if ((b - a) >= (d - c) && ((b - a) - (d - c)) % 3 == 0) cout << 1; else cout << 0;
                continue;
            }
            if ((b - B1) >= (d - B2) && ((b - B1) - (d - B2)) % 3 == 0) cout << 1; else cout << 0;
            continue;
        }
        if (A == 0) {
            if (d - B2 < b - a + 1) cout << 1; else cout << 0;
            continue;
        }
        if (d - B2 <= b - B1) cout << 1; else cout << 0;
    }
    cout << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
string s, t;
int sufs[100005], suft[100005], sums[100005], sumt[100005], q;
int solve(int sl, int sr, int tl, int tr) {
    int sa = min(sufs[sr], sr - sl + 1), ta = min(suft[tr], tr - tl + 1);
    int sb = sums[sr] - sums[sl - 1], tb = sumt[tr] - sumt[tl - 1];
    //cout << sa << " " << sb << " " << ta << " " << tb << endl;
    if(sb <= tb && (tb - sb) % 2 == 0) {
        if(sb == tb) {
            if(sa < ta) return 0;
            return ((sa - ta) % 3) == 0;
        }else if(sb == 0) {
            return sa > ta;
        }else return sa >= ta;
    }else return 0;
}
int main() {
    //freopen("in.txt", "r", stdin);
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'B' || s[i] == 'C') sums[i + 1] = sums[i] + 1; else sums[i + 1] = sums[i];
    }
    for(int i = 0; i < t.size(); ++i) {
        if(t[i] == 'B' || t[i] == 'C') sumt[i + 1] = sumt[i] + 1; else sumt[i + 1] = sumt[i];
    }
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'A') sufs[i + 1] = sufs[i] + 1; else sufs[i + 1] = 0;
    }
    for(int i = 0; i < t.size(); ++i) {
        if(t[i] == 'A') suft[i + 1] = suft[i] + 1; else suft[i + 1] = 0;
    }
    // for(int i = 0; i < s.size(); ++i) {
    //     cout << sums[i + 1] << " ";
    // }cout << endl;
    // for(int i = 0; i < t.size(); ++i) {
    //     cout << sumt[i + 1] << " ";
    // }cout << endl;
    scanf("%d", &q);
    while(q--) {
        int sl, sr, tl, tr;
        scanf("%d%d%d%d", &sl, &sr, &tl, &tr);
        cout << solve(sl, sr, tl, tr);
    }
    return 0;
}

#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<assert.h>
#include<queue>
#include<string>
#define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++)
#define per(i,j,k) for(int i=(int)j;i>=(int)k;i--)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
const int N=110000;
char s[N],t[N];
int n,m;
int Q;
int s0[N],s1[N],t0[N],t1[N];
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	scanf("%s",t+1);m=strlen(t+1);
	rep(i,1,n){
		s0[i]=(s0[i-1]+(s[i]!='A'));
		s1[i]=s1[i-1]+1;
		if(s[i]!='A')s1[i]=0;
	}
	rep(i,1,m){
		t0[i]=(t0[i-1]+(t[i]!='A'));
		t1[i]=t1[i-1]+1;
		if(t[i]!='A')t1[i]=0;
	}
	scanf("%d",&Q);
	while(Q--){
		int l1,r1,l2,r2;
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		int ns=s0[r1]-s0[l1-1];
		int nt=t0[r2]-t0[l2-1];
		int es=min(s1[r1],r1-l1+1);
		int et=min(t1[r2],r2-l2+1);
		//printf("%d %d %d %d",ns,nt,es,et);
		if(!ns&&nt){
			if(!(es>et)){
				putchar('0');
				continue;
			}
		}
		if(ns>nt)putchar('0');
		else if(ns==nt){
			if(es>=et&&(es-et)%3==0)putchar('1');
			else putchar('0');
		}
		else{
			if((nt-ns)%2==0&&es>=et)putchar('1');
			else putchar('0');
		}
	}
	puts("");
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int BS[100005];
int BT[100005];
char S[100005];
char T[100005];
int SN, TN;
int ans[100005];
int AS[100005];
int AT[100005];

int main() {
	scanf(" %s", S+1);
	scanf(" %s", T+1);
	SN = (int)strlen(S+1);
	TN = (int)strlen(T+1);
	S[0] = T[0] = 0;

	for(int i = 1; i <= SN; i++) {
		BS[i] = BS[i - 1];
		if(S[i] == 'B' || S[i] == 'C') BS[i]++;
	}
	for(int i = 1; i <= TN; i++) {
		BT[i] = BT[i - 1];
		if(T[i] == 'B' || T[i] == 'C') BT[i]++;
	}
	for(int i = 1; i <= SN; i++) {
		if(S[i] != 'A') AS[i] = 0;
		else AS[i] = AS[i - 1] + 1;
	}
	for(int i = 1; i <= TN; i++) {
		if(T[i] != 'A') AT[i] = 0;
		else AT[i] = AT[i - 1] + 1;
	}

	int Q; scanf("%d", &Q);
	for(int q = 0; q < Q; q++) {
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		int scnt = BS[b] - BS[a - 1];
		int tcnt = BT[d] - BT[c - 1];
		if(scnt > tcnt) { ans[q] = 0; continue; }
		if(scnt % 2 != tcnt % 2) { ans[q] = 0; continue; }
		int x = min(b - a + 1, AS[b]), y = min(d - c + 1, AT[d]);
		if(x < y) { ans[q] = 0; continue; }
		if(x > y && (x - y) % 3 && scnt + 2 > tcnt) { ans[q] = 0; continue; }
		if(x == y && x == b - a + 1 && y != d - c + 1) { ans[q] = 0; continue; }
		ans[q] = 1;
	}
	for(int i = 0; i < Q; i++) printf("%d", ans[i]);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int int64_t

struct StringMachine {
private:
  int N;
  string s;
  vector<int> cumSumB;
  vector<int> contA;
public:
  StringMachine(string s_) {
    s = s_;
    N = s.length();
    for(int i=0;i<N;i++) {
      if(s[i]=='C')s[i]='B';
    }

    cumSumB = vector<int>(N+1);
    cumSumB[0]=0;
    for(int i=0;i<N;i++) {
      cumSumB[i+1]=cumSumB[i];
      if(s[i]=='B')cumSumB[i+1]++;
    }

    contA = vector<int>(N);
    int curA = 0;
    for(int i=0;i<N;i++) {
      if(s[i]=='A')curA++; else curA=0;
      contA[i]=curA;
    }
  }

  int getTailA(int l, int r) {
    return min(contA[r-1], r-l);
  }

  int getTotalB(int l, int r) {
    return cumSumB[r]-cumSumB[l];
  }
};

StringMachine getSM() {
  string x;
  cin>>x;
  return StringMachine(x);
}

bool canDo(int da, int db) {
  if(db<0 || db%2!=0) return false;
  if(da<0) return false;
  if(da%3!=0 && db<2) return false;
  return true;
}

main() {
  //freopen("input.txt", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  StringMachine s = getSM();
  StringMachine t = getSM();

  int n,a,b,c,d;
  cin>>n;
  for(int i=0;i<n;i++) {
    cin>>a>>b>>c>>d;

    int a1 = s.getTailA(a-1,b);
    int b1 = s.getTotalB(a-1,b);
    int a2 = t.getTailA(c-1,d);
    int b2 = t.getTotalB(c-1,d);

    int db = b2-b1;
    int da = a1-a2;
    if (b1==0 && b2>0 && da==0) {
      cout<<"0";
    } else {
      if(canDo(da, db))cout<<"1"; else cout<<"0";
    }
  }

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+20;
string S, T;
int Q, s[N], so[N], sz[N], t[N], to[N], tz[N];

int check(int os, int zs, int ot, int zt){

    if (os == ot)
    {
    // cout << "os == ot\n";
        if (zs == zt) return 1;
        if (zs > zt && (zs - zt) % 3 == 0) return 1;
        return 0;
    }
    if (os > ot) return 0;
    // (os < ot)
    // cout << "os < ot\n";
        if ((ot - os) % 2 != 0) return 0;
            if (os > 0 && zs == zt) return 1;
            if (zs > zt) return 1;
    return 0;
}
/*
CCBACACBCCCBBAAC
CACCAAABAACBBBBAC
1
14 15 12 16
*/

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> S >> T;

    for (int i = 1; i <= S.size(); i++)
    {
        if (S[i-1] == 'A')
            s[i] = 0;
        else
            s[i] = 1;
        so[i] = so[i-1]+s[i];
        sz[i] = s[i] ? 0 : sz[i-1]+1;
    }

    for (int i = 1; i <= T.size(); i++)
    {
        if (T[i-1] == 'A')
            t[i] = 0;
        else
            t[i] = 1;
        to[i] = to[i-1] + t[i];
        tz[i] = t[i] ? 0 : tz[i-1]+1;
    }
    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int os = so[b] - so[a-1];
        int zs = sz[b] > b-a+1 ? b-a+1 : sz[b];
        int ot = to[d] - to[c-1];
        int zt = tz[d] > d-c+1 ? d-c+1 : tz[d];
        cout << check(os, zs, ot, zt);
    }
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int dps[100005];
int dpt[100005];

int getS (int pos) {
    return pos - dps[pos];
}

int getT (int pos) {
    return pos - dpt[pos];
}

int main() {
//    ifstream fin ("date.in");
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); ++i) {
        dps[i + 1] = dps[i];
        if (s[i] == 'A') {
            dps[i + 1] += 1;
        }
    }
    for (int i = 0; i < t.size(); ++i) {
        dpt[i + 1] = dpt[i];
        if (t[i] == 'A') {
            dpt[i + 1] += 1;
        }
    }
    int q;
    cin >> q;
    for (int i = 1; i <= q; ++i) {
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        int diff = getT(r2) - getT(l2 - 1) - getS(r1) + getS(l1 - 1);
        if (diff < 0 or diff % 2) {
            cout << 0;
            continue;
        }
        int currentS = 0;
        for (int power = 20; power >= 0; --power) {
            if (r1 - currentS - (1 << power) >= l1 - 1 and dps[r1] - dps[r1 - currentS - (1 << power)] == currentS + (1 << power)) {
                currentS += (1 << power);
            }
        }
        int currentT = 0;
        for (int power = 20; power >= 0; --power) {
            if (r2 - currentT - (1 << power) >= l2 - 1 and dpt[r2] - dpt[r2 - currentT - (1 << power)] == currentT + (1 << power)) {
                currentT += (1 << power);
            }
        }
        if (currentS < currentT) {
            cout << 0;
            continue;
        }
        if ((currentS - currentT) % 3 and diff == 0) {
            cout << 0;
            continue;
        }
        if (currentS == r1 - l1 + 1 and currentS == currentT and diff) {
            cout << 0;
            continue;
        }
        cout << 1;
    }
    return 0;
}

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=100050;
char s[maxn],t[maxn];
int sum1[maxn],sum2[maxn];
int pre1[maxn],pre2[maxn],res[maxn];
int q;

void solve(){
	scanf("%s %s",s+1,t+1);
	int len_s=strlen(s+1),len_t=strlen(t+1);
	for(int i=1;i<=len_s;i++){
		sum1[i]=sum1[i-1]+(s[i]=='B'||s[i]=='C');
		pre1[i]=(s[i]=='B'||s[i]=='C')?i:pre1[i-1];
	}
	for(int i=1;i<=len_t;i++){
		sum2[i]=sum2[i-1]+(t[i]=='B'||t[i]=='C');
		pre2[i]=(t[i]=='B'||t[i]=='C')?i:pre2[i-1];
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int l,r,a,b;
		scanf("%d %d %d %d",&l,&r,&a,&b);
		res[i]=1;
		int all1=sum1[r]-sum1[l-1],all2=sum2[b]-sum2[a-1];
		int tot1=r-max(pre1[r],l-1),tot2=b-max(pre2[b],a-1);
		if(all1>all2)	res[i]=0;
		if((all2-all1)%2)	res[i]=0;
		if(tot1<tot2)	res[i]=0;
		int ret1=(all2-all1)/2,ret2=(tot1-tot2)%3;
		if(ret2&&!ret1)	res[i]=0;
		if(all1==0&&all2!=0&&tot1==tot2)	res[i]=0;
	}
	for(int i=1;i<=q;i++)	printf("%d",res[i]);
}
int main(){
	solve();
	return 0;
}
/*
CCBACACBCCCBBAAC
CACCAAABAACBBBBAC

BAA
BAACB
13 15 8 12

00001100101000010000
*/

#include<iostream>
#include<cstdio>
#include<algorithm>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define fd(i,r,l) For(int i=r;i>=l;i--)
#define N 100005
using namespace std;
char s[N],t[N];
int a1[N],b1[N],a2[N],b2[N],x1,y1,x2,y2,sa,sb,ta,tb;
bool pd()
{
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	sa=min(y1-x1+1,a1[y1]);sb=b1[y1]-b1[x1-1];
	ta=min(y2-x2+1,a2[y2]);tb=b2[y2]-b2[x2-1];
	if(sb>tb || (sb+tb)%2==1 || sa<ta) return false;
	if(sb==tb && sa%3!=ta%3 || sb==0 && sa==ta && sb!=tb) return false;
	/*if(sb>tb || sa<ta || (sb%2)!=(tb%2)) return false;
	if(sb==tb && !(sa-ta)%3) return true;
	if(sb<tb && ((sa-ta)!=0 || sb!=0) ) return true;
	return false;*/
	return true;
}
int main()
{
	//freopen("string.in","r",stdin);
	//freopen("string.in","w",stdout);
	scanf("%s%s",s+1,t+1);
	for(int i=1;s[i]!=0;i++)
	{
		if(s[i]=='A') a1[i]=a1[i-1]+1;
		b1[i]=b1[i-1]+(s[i]!='A');
	}
	for(int i=1;t[i]!=0;i++)
	{
		if(t[i]=='A') a2[i]=a2[i-1]+1;
		b2[i]=b2[i-1]+(t[i]!='A');
	}
	int Q;scanf("%d",&Q);
	fo(i,1,Q)
	{
		if (pd()) printf("1"); else printf("0");
	}
}

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
const int maxn = 100010;
const int mod = 1e9 + 7;
const int INF = 999999999;
double eps = 1e-8;
typedef long long LL;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

char s[maxn], t[maxn];
int sums[maxn], sumt[maxn], lasts[maxn], lastt[maxn];

void init() {
    sums[0] = sumt[0] = 0;
    int lens = strlen(s + 1), lent = strlen(t + 1);
    for(int i = 1, tempb = 0, tempa = 0;i <= lens;i++) {
        if(s[i] == 'C') s[i] = 'B';
        if(s[i] == 'B') tempb++, tempa = 0;
        else tempa++;
        sums[i] = tempb;
        lasts[i] = tempa;
        //cout << sums[i] << " ";
    }
    //cout << endl;
    for(int i = 1, tempb = 0, tempa = 0;i <= lent;i++) {
        if(t[i] == 'C') t[i] = 'B';
        if(t[i] == 'B') tempb++, tempa = 0;
        else tempa++;
        sumt[i] = tempb;
        lastt[i] = tempa;
    }
}

void solve() {
    cin >> s + 1 >> t + 1;
    int n;
    cin >> n;
    init();
    //cout << s + 1 << endl;
    //cout << t + 1 << endl;
    for(int i = 1, ls, rs, lt, rt;i <= n;i++) {
        scanf("%d %d %d %d", &ls, &rs, &lt, &rt);
        int sb = sums[rs] - sums[ls - 1], tb = sumt[rt] - sumt[lt - 1];
        int sa = min(lasts[rs], rs - ls + 1), ta = min(lastt[rt], rt - lt + 1);
        int ok = 1;
        if(sb > tb || sb % 2 != tb % 2) ok = 0;
        else if(sa < ta) ok = 0;
        else if( sb == tb && (sa - ta) % 3 != 0) ok = 0;
        else if(sb < tb && sa == ta && sb == 0) ok = 0;
        if(ok) printf("1");
        else printf("0");
    }
    cout << endl;
}

int main() {
    solve();
    int mark_EOF;
    if(scanf("%d", &mark_EOF) == EOF) return 0;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
string s[2];
int cntA[2][100005];
int suffixA[2][100005];
string res;
int main(){
    iostream::sync_with_stdio(0);
    cin >> s[0] >> s[1];
    int n = s[0].size();
    int m = s[1].size();
    s[0] = '0' + s[0];
    s[1] = '0' + s[1];
    for(int i=1;i<=n;i++)
        cntA[0][i] = (s[0][i] == 'A') + cntA[0][i-1],
        suffixA[0][i] = (s[0][i] == 'A' ? 1 + suffixA[0][i-1] : 0);
    for(int i=1;i<=m;i++)
        cntA[1][i] = (s[1][i] == 'A') + cntA[1][i-1],
        suffixA[1][i] = (s[1][i] == 'A' ? 1 + suffixA[1][i-1] : 0);
    int q;
    cin >> q;
    while(q--){
        int x,y,z,t;
        cin >> x >> y >> z >> t;
        int xa = cntA[0][y] - cntA[0][x-1];
        int xb = cntA[1][t] - cntA[1][z-1];
        int ya = y - x + 1 - xa;
        int yb = t - z + 1 - xb;
        if (ya > yb){
            res.push_back('0');
        }
        else if ((yb - ya) % 2 == 1){
            res.push_back('0');
        }
        else{
            int suffa = min(suffixA[0][y], y - x + 1);
            int suffb = min(suffixA[1][t], t - z + 1);
            if (suffa < suffb){
                res.push_back('0');
            }
            else if (ya == yb){
                if (suffa % 3 != suffb % 3)
                    res.push_back('0');
                else
                    res.push_back('1');
            }
            else{
                if (suffa == suffb){
                    if (!ya && yb)  res.push_back('0');
                    else    res.push_back('1');;
                    continue;
                }
                bool ok = 0;
                for(int mjk=0;suffa - mjk >= suffb;mjk++){
                    if ((suffa - mjk + 6) % 3 == suffb % 3){
                        res.push_back('1');
                        ok = 1;
                        break;
                    }
                }
                if (!ok)
                    res.push_back('0');
            }
        }
    }
    cout << res;
}

#include <bits/stdc++.h>
using namespace std;
const int N(100011);
char s[N], t[N];
int nbs[N], nbt[N], ras[N], rat[N], ls, lt;
void pre() {
	int i;
	ls = strlen(s + 1);
	lt = strlen(t + 1);
	for (i = 1; i <= ls; ++i)
		nbs[i] = nbs[i - 1] + (s[i] == 'B' || s[i] == 'C');
	for (i = 1; i <= lt; ++i)
		nbt[i] = nbt[i - 1] + (t[i] == 'B' || t[i] == 'C');
	for (i = 1; i <= ls; ++i)
		ras[i] = (s[i] == 'A') * (1 + ras[i - 1]);
	for (i = 1; i <= lt; ++i)
		rat[i] = (t[i] == 'A') * (1 + rat[i - 1]);
}
bool query(int sl, int sr, int tl, int tr) {
	int cnbs(nbs[sr] - nbs[sl - 1]), cnbt(nbt[tr] - nbt[tl - 1]);
	int cras(min(ras[sr], sr - sl + 1)), crat(min(rat[tr], tr - tl + 1));
	if (!(cnbt >= cnbs && (cnbt - cnbs) % 2 == 0) || cras < crat)
		return false;
	else if (cnbs == 0 && cnbt == 0)
		return (cras - crat) % 3 == 0;
	else if (cnbs == 0 && cnbt != 0)
		return cras > crat;
	else
		return (cras - crat) % 3 == 0 || cnbt > cnbs;
}
int main() {
	int q, sl, sr, tl, tr;
	scanf("%s%s", s + 1, t + 1);
	pre();
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d%d%d", &sl, &sr, &tl, &tr);
		printf("%d", int(query(sl, sr, tl, tr)));
	}
	printf("\n");
	return 0;
}

/*
 * Author : Remilia Scarlet
 */

// #pragma comment(linker, "/STACK:102400000,102400000")

#include <bits/stdc++.h>

#define For(i,l,r) for(int _r=r,i=l;i<=_r;++i)
#define rep(i,l,r) for(int _r=r,i=l;i<_r;++i)
#define dto(i,r,l) for(int _l=l,i=r;i>=_l;--i)
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define oo (c=getchar())
#define SZ(V) (int(V.size()))
#define ALL(V) V.begin(),V.end()

using namespace std;

typedef double db;
typedef long long LL;
typedef pair<int ,int> PII;
typedef vector<int> VI;
typedef complex<db> cpx;
typedef vector<PII> VII;
// typedef __int128 bigint;

int ran(){return (rand()<<15)+rand();}

int IN(){
	int x=0;char c;
	for(;oo<48 && c^'-' || c>57;);bool f=c=='-';if(f)oo;
	for(;c>47 && c<58;oo)x=(x<<1)+(x<<3)+c-48;return f?-x:x;
}
void print(int x,char en='\n'){
	printf("%d",x);if(en)putchar(en);
}

void hello(){
	freopen("remi.in","r",stdin);
//	freopen("remi.out","w",stdout);
//	srand(time(0));
}

int Q,n,m;
typedef int Arr[100010];
Arr pa,pb,la,lb;
char a[100010],b[100010];

void pret(){
	n = strlen(a+1);
	m = strlen(b+1);
	For(i,1,n){
		if(a[i] == 'C')a[i] = 'B';
		pa[i] = pa[i-1] + (a[i] == 'B');
		la[i] = a[i]=='A'?la[i-1]+1:0;
	}
	For(i,1,m){
		if(b[i] == 'C')b[i] = 'B';
		pb[i] = pb[i-1] + (b[i] == 'B');
		lb[i] = b[i]=='A'?lb[i-1]+1:0;
	}
}

PII geta(int l,int r){
	PII res;
	res.x = pa[r]-pa[l-1];
	res.y = min(la[r],r-l+1);
	return res;
}

PII getb(int l,int r){
	PII res;
	res.x = pb[r]-pb[l-1];
	res.y = min(lb[r],r-l+1);
	return res;
}

int main(int argc, char* argv[]){
//	hello();
	scanf("%s%s",a+1,b+1);
	pret();
	Q = IN();
	For(i,1,Q){
		int l = IN(),r = IN(),ll = IN(),rr = IN();
		PII it = geta(l,r);
		PII ti = getb(ll,rr);
		if(it.x>ti.x)putchar('0');
		else if(it.x==ti.x){
			if(it.y>=ti.y && (it.y-ti.y)%3==0)putchar('1');
			else putchar('0');
		}else{
			if(ti.x-it.x&1)putchar('0');else{
				if(it.y>ti.y || it.y==ti.y && it.x)putchar('1');else putchar('0');
			}
		}
	}
}

#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define N 200005
//#define M 1000005
#define pi 3.14159265359
#define cpdd const pdd
#define MAXN 100005
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
int main(){
	char c[100005];
	scanf("%s",c);
	int cnt[100005];
	int last[100005];
	cnt[0]=0;
	for(int i=0;c[i]!=0;i++){
		cnt[i+1]=cnt[i];
		if(c[i]!='A'){
			cnt[i+1]++;
		}
		else{
			last[i+1]=last[i]+1;
		}
	}
	char c2[100005];
	scanf("%s",c2);
	int cnt2[100005];
	int last2[100005];
	cnt2[0]=0;
	MEM(last2);
	for(int i=0;c2[i]!=0;i++){
		cnt2[i+1]=cnt2[i];
		if(c2[i]!='A'){
			cnt2[i+1]++;
		}
		else{
			last2[i+1]=last2[i]+1;
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		//printf("%d %d\n",cnt[b]-cnt[a-1],cnt2[d]-cnt2[c-1]);
		int x=cnt[b]-cnt[a-1];
		int y=cnt2[d]-cnt2[c-1];
		int aa=min(last[b],b-a+1),ba=min(last2[d],d-c+1);
		if(aa<ba)
		printf("0");
		else if(x==0&&y!=0&&aa==ba)
		printf("0");
		else{
			aa-=ba;
			aa%=3;
			if(aa)
			x+=2;
			if(x>y)
			printf("0");
			else if((x&1)!=(y&1))
			printf("0");
			else
			printf("1");
		}
	}
}
/*
BC
ACC
AABC
CC
ABC
AACC*/

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <stack>
#include <memory>

using namespace std;

bool f(array<int, 2> p1, array<int, 2> p2) {
	//cout << "[" << p1[1] << ' ' << p2[1] << "]\n";
	if (p1[0] > p2[0] || ((p1[0] ^ p2[0]) & 1) || p1[1] < p2[1])
		return false;
	if (p1[0] == p2[0])
		return (p1[1] - p2[1]) % 3 == 0;
	if (!p1[0]) { // p2[0]
		return f({ 2, p1[1] - 1 }, p2) || (p1[1] >= 2 && f({ 2, p1[1] - 2 }, p2)) || (p1[1] >= 3 && f({ 2, p1[1] - 3 }, p2));
	}
	return true;
}

struct DS {
	string s;
	vector<int> cs, last;
	DS() {
		cin >> s;
		cs.resize(s.size());
		last.resize(s.size());
		for (int i = 0; i < s.size(); ++i) {
			cs[i] = (i ? cs[i - 1] : 0) + (s[i] != 'A');
			last[i] = s[i] != 'A' ? i : i ? last[i - 1] : -1;
		}
	}
	array<int, 2> query(int i, int j) {
		if (last[j] < i)
			return{ 0, j - i + 1 };
		return{ cs[last[j]] - (i ? cs[i - 1] : 0), j - last[j] };
	}
};

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

	DS ds1;
	DS ds2;

	int q;
	cin >> q;
	while (q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		--a; --b; --c; --d;
		cout << f(ds1.query(a, b), ds2.query(c, d));
	}
	return 0;
}

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;

const int MAXN=100005;
string ax,bx;
int q,pre1[MAXN],pre2[MAXN],pre3[MAXN],pre4[MAXN],a,b,c,d;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>ax>>bx>>q;
	for(int i=1;i<=ax.size();++i) {
		if(ax[i-1]=='A') {
			pre1[i]=pre1[i-1]+1;
			pre2[i]=pre2[i-1];
		}
		else {
			pre1[i]=0;
			pre2[i]=pre2[i-1]+1;
		}
	}
	for(int i=1;i<=bx.size();++i) {
		if(bx[i-1]=='A') {
			pre3[i]=pre3[i-1]+1;
			pre4[i]=pre4[i-1];
		}
		else {
			pre3[i]=0;
			pre4[i]=pre4[i-1]+1;
		}
	}
	for(int i=0;i<q;++i) {
		int xa,xb,ya,yb;
		cin>>a>>b>>c>>d;
		xa=min(pre1[b],b-a+1);
		ya=min(pre3[d],d-c+1);
		xb=pre2[b]-pre2[a-1];
		yb=pre4[d]-pre4[c-1];
		if(xa<ya) {
			cout<<0;
			continue;
		}
		if(xa>ya&&(xa-ya)%3!=0) {
			xb+=2;
		}
		if(xb<=yb&&(yb-xb)%2==0)
			cout<<1;
		else cout<<0;
	}
	cout<<endl;

}

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)
#define sz(x) (int)(x).size()

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;

int ps[100007], pt[100007];
int ts[100007], tt[100007];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	string s, t;
	cin >> s >> t;

	int q;
	cin >> q;

	ps[0] = (s[0] != 'A' ? 1 : 0);
	ts[0] = 1 - ps[0];
	forb(i, sz(s) - 1) {
		ps[i] += ps[i - 1];
		ps[i] += (s[i] != 'A') ? 1 : 0;
		ts[i] = (s[i] == 'A') ? ts[i - 1] + 1 : 0;
	}

	pt[0] = (t[0] != 'A' ? 1 : 0);
	tt[0] = 1 - pt[0];
	forb(i, sz(t) - 1) {
		pt[i] += pt[i - 1];
		pt[i] += (t[i] != 'A') ? 1 : 0;
		tt[i] = (t[i] == 'A') ? tt[i - 1] + 1 : 0;
	}

	fora(_, q) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		--a; --b; --c; --d;

		int trs = min(ts[b], b - a + 1);
		int trt = min(tt[d], d - c + 1);

		int have = ps[b] - (a == 0 ? 0 : ps[a - 1]);
		int need = pt[d] - (c == 0 ? 0 : pt[c - 1]);

		//cout << dbgs4(trs, trt, have, need) << endl;

		if (have > need) {
			cout << '0';
			continue;
		}

		if (trt > trs) {
			cout << '0';
			continue;
		}

		if ((need - have) % 2 != 0) {
			cout << '0';
			continue;
		}

		if ((trt != trs) && (have == need)) {
			cout << '0';
			continue;
		}

		if (have == 0 && trs == 1 && trt != 0) {
			cout << '0';
			continue;
		}

		cout << '1';
	}
	cout << endl;

}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <iomanip>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <time.h>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-6;

string S, T;
int CS[MAXN], CT[MAXN], AS[MAXN], AT[MAXN];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	cin >> S >> T;
	FOR(i, 1, SZ(S) + 1)
	{
		CS[i] = CS[i - 1] + (S[i - 1] > 'A');
		AS[i] = S[i - 1] > 'A' ? 0 : AS[i - 1] + 1;
	}
	FOR(i, 1, SZ(T) + 1)
	{
		CT[i] = CT[i - 1] + (T[i - 1] > 'A');
		AT[i] = T[i - 1] > 'A' ? 0 : AT[i - 1] + 1;
	}
	int q;
	cin >> q;
	while (q--)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if (CS[b] - CS[a - 1] > CT[d] - CT[c - 1] ||
			((CT[d] - CT[c - 1] - CS[b] + CS[a - 1]) & 1))
		{
			cout << 0;
			continue;
		}
		if (CS[b] - CS[a - 1] == CT[d] - CT[c - 1])
		{
			cout << (AT[d] <= AS[b]) && ((AS[b] - AT[d]) % 3 == 0);
			continue;
		}
		if (CS[b] - CS[a - 1])
		{
			cout << (AT[d] <= AS[b]);
			continue;
		}
		cout << (AT[d] < AS[b]);
	}
	return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define Ys { putchar('1'); continue; }
#define No { putchar('0'); continue; }

using namespace std;

const int N=100010;

char s[N],t[N];
int ps[N],pt[N],ls[N],lt[N],q,n,m;

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	scanf("%s",t+1); m=strlen(t+1);
	for(int i=1;i<=n;i++){
		ps[i]=ps[i-1]; ls[i]=ls[i-1];
		if(s[i]!='A') ps[i]++,ls[i]=i;
	}
	for(int i=1;i<=m;i++){
		pt[i]=pt[i-1]; lt[i]=lt[i-1];
		if(t[i]!='A') pt[i]++,lt[i]=i;
	}
	scanf("%d",&q);
	while(q--){
		int l,r,L,R;
		scanf("%d%d%d%d",&l,&r,&L,&R);
		if(ps[r]-ps[l-1]>pt[R]-pt[L-1]) No;
		if(ps[r]-ps[l-1]<pt[R]-pt[L-1]){
			if((pt[R]-pt[L-1])-(ps[r]-ps[l-1])&1) No;
			if(lt[R]==R && ls[r]==r) Ys;
			if(ls[r]!=r) Ys;
			if(lt[R]!=R) No;
			int t1=ls[r]>=l?r-ls[r]:r-l+1,t2=lt[R]>=L?R-lt[R]:R-L+1;
			if(t1<t2) No;
			Ys;
		}
		int t1=ls[r]>=l?r-ls[r]:r-l+1,t2=lt[R]>=L?R-lt[R]:R-L+1;
		if(t2>t1) No;
		if((t1-t2)%3==0) Ys;
		No;
	}
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    string s, t;
    getline(cin,s);
    getline(cin,t);
    int Q;
    cin >> Q;
    int a,b,c,d;
    vector<int> snuma (s.size()+1,0);
    vector<int> snumb (s.size()+1,0);
    vector<int> tnuma (t.size()+1,0);
    vector<int> tnumb (t.size()+1,0);
    for(int i = 1; i < s.size()+1; i++){
        snuma[i] = snuma[i-1];
        snumb[i] = snumb[i-1];
        if(s[i-1] == 'A'){
            snuma[i]++;
        }else{
            snumb[i]++;
            snuma[i] = 0;
        }
    }
    for(int i = 1; i < t.size()+1; i++){
        tnuma[i] = tnuma[i-1];
        tnumb[i] = tnumb[i-1];
        if(t[i-1] == 'A'){
            tnuma[i]++;
        }else{
            tnumb[i]++;
            tnuma[i] = 0;
        }
    }
    int snumb1,snumta, tnumb1, tnumta;
    for(int i = 0; i < Q; i++){
        cin >> a >> b >> c >> d;
        snumb1 = snumb[b]-snumb[a-1];
        tnumb1 = tnumb[d]-tnumb[c-1];
        snumta = min((b+1-a),snuma[b]);
        tnumta = min((b+1-a),tnuma[d]);
        bool possible = true;
        if(snumb1 == tnumb1){
            possible = (snumta >= tnumta && (snumta-tnumta%3) ==0);
            // cannot add any Bs
        }else if(snumb1 > tnumb1){
            // need to remove Bs
            possible = false;
        }else{
            if(snumb1==0){
                possible = tnumta < snumta;
            }else{
                possible = tnumta <= snumta;
            }
            possible = possible && ((tnumb1 - snumb1)%2 == 0);
            // must add B's
        }
        //cout << snumb1 << ' ' << snumc1 << ' ' << tnumb1 << ' ' << tnumc1 << endl;
        if(possible){
            cout << 1;
        }else{
            cout << 0;
        }
        //cout << endl;
    }
    cout << endl;
}

#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin())
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CASE(x) int x; cin >> x; while (x--)
#define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc)
using namespace std;
using namespace __gnu_pbds;
namespace {
	const int MOD107 = 1000000007;
	const int MOD998 = 998244353;
	using ll = long long;
	using ull = unsigned long long;
	using pii = pair<int, int>;
	using pll = pair<ll, ll>;
	template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
	template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
	template <class T> using maxheap = priority_queue<T, vector<T>, less<T>>;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
	struct Modular {
	private:
		long long MODVALUE = 0;
		long long val = 0;

		Modular initModular(long long val) const { return Modular(val, MODVALUE); }

	#ifdef LOCAL
		inline void validate() const {
			assert(MODVALUE != 0);
		}

		inline void validate(const Modular& other) const {
			assert(MODVALUE != 0);
			assert(MODVALUE == other.MODVALUE);
			other.validate();
		}
	#else
		inline void validate() const { }
		inline void validate(const Modular& other) const { }
	#endif

	public:
		explicit operator long long() const { return val; }

		template<class T> Modular& operator = (const T& other) { val = other; return *this; }
		template<class T> void setMod(const T& MOD) { MODVALUE = MOD; }

		bool operator == (const Modular& other) { validate(other); return val == other.val; }
		bool operator != (const Modular& other) { return !(*this == other); }
		template<class T> bool operator == (const T& other) { return *this == initModular(other); }
		template<class T> bool operator != (const T& other) { return *this != initModular(other); }
		template<class T> friend bool operator == (const T& other, const Modular& m) { return m.initModular(other) == m; }
		template<class T> friend bool operator != (const T& other, const Modular& m) { return m.initModular(other) != m; }

		bool operator <  (const Modular& other) { validate(other); return val <  other.val; }
		bool operator <= (const Modular& other) { validate(other); return val <= other.val; }
		bool operator >  (const Modular& other) { validate(other); return val >  other.val; }
		bool operator >= (const Modular& other) { validate(other); return val >= other.val; }
		template<class T> bool operator <  (const T& other) { return *this <  initModular(other); }
		template<class T> bool operator <= (const T& other) { return *this <= initModular(other); }
		template<class T> bool operator >  (const T& other) { return *this >  initModular(other); }
		template<class T> bool operator >= (const T& other) { return *this >= initModular(other); }
		template<class T> friend bool operator <  (const T& other, const Modular& m) { return m.initModular(other) <  m; }
		template<class T> friend bool operator <= (const T& other, const Modular& m) { return m.initModular(other) <= m; }
		template<class T> friend bool operator >  (const T& other, const Modular& m) { return m.initModular(other) >  m; }
		template<class T> friend bool operator >= (const T& other, const Modular& m) { return m.initModular(other) >= m; }

		Modular& operator += (const Modular& other) { validate(other); val += other.val; val %= MODVALUE; return *this; }
		Modular  operator +  (const Modular& other) { Modular tmp = *this; return tmp += other; }
		template<class T> Modular& operator += (const T& other) { return *this += initModular(other); }
		template<class T> Modular  operator +  (const T& other) { return *this +  initModular(other); }
//		template<class T> friend Modular operator += (const T& other, const Modular& m) { return m.initModular(other) += m; }
		template<class T> friend Modular operator +  (const T& other, const Modular& m) { return m.initModular(other) +  m; }

		Modular& operator ++()    { return *this += 1; }
		Modular  operator ++(int) { Modular tmp = *this; ++*this; return tmp; }

		Modular  operator -  () const { return initModular(-val); }
		Modular& operator -= (const Modular& other) { validate(other); val -= other.val; val += MODVALUE; val %= MODVALUE; return *this;}
		Modular  operator -  (const Modular& other) { Modular tmp = *this; return tmp -= other; }
		template<class T> Modular& operator -= (const T& other) { return *this -= initModular(other); }
		template<class T> Modular  operator -  (const T& other) { return *this -  initModular(other); }
//		template<class T> friend Modular operator -= (const T& other, const Modular& m) { return m.initModular(other) -= m; }
		template<class T> friend Modular operator -  (const T& other, const Modular& m) { return m.initModular(other) -  m; }

		Modular& operator --()    { return *this -= 1; }
		Modular  operator --(int) { Modular tmp = *this; --*this; return tmp; }

		Modular& operator *= (const Modular& other) { validate(other); val *= other.val; val %= MODVALUE; val += MODVALUE; val %= MODVALUE; return *this; }
		Modular  operator *  (const Modular& other) { Modular tmp = *this; return tmp *= other; }
		template<class T> Modular& operator *= (const T& other) { return *this *= initModular(other); }
		template<class T> Modular  operator *  (const T& other) { return *this *  initModular(other); }
//		template<class T> friend Modular operator *= (const T& other, const Modular& m) { return m.initModular(other) *= m; }
		template<class T> friend Modular operator *  (const T& other, const Modular& m) { return m.initModular(other) *  m; }

		Modular pow(long long power) const {
			Modular m = *this, ans = initModular(1);
			while (power) {
				if (power & 1) ans *= m;
				m *= m;
				power >>= 1;
			}
			return ans;
		}
		Modular pow(const Modular& other) const { return pow(other.val); }
		Modular inv() const { return pow(MODVALUE-2); }

		Modular& operator /= (const Modular& other) { val *= other.inv().val; val %= MODVALUE; return *this; }
		Modular  operator /  (const Modular& other) { Modular tmp = *this; return tmp /= other; }
		template<class T> Modular& operator /= (const T& other) { return *this /= initModular(other); }
		template<class T> Modular  operator /  (const T& other) { return *this /  initModular(other); }
//		template<class T> friend Modular operator /= (const T& other, const Modular& m) { return m.initModular(other) /= m; }
		template<class T> friend Modular operator /  (const T& other, const Modular& m) { return m.initModular(other) /  m; }

		friend istream& operator >> (istream& in, Modular& m) { in >> m.val; m.val %= m.MODVALUE; m.val += m.MODVALUE; m.val %= m.MODVALUE; return in; }
		friend ostream& operator << (ostream& out, const Modular& m) { return out << m.val; }

		Modular() { val = 0; MODVALUE = 0; }
		Modular(long long val, long long MOD) : MODVALUE(MOD), val((val % MOD + MOD) % MOD) { }
	};
	using Mint = Modular;
	inline ll pow(ll b, ll p, ll mod) {
		b %= mod;
		ll ans = 1;
		for (; p > 0; p >>= 1) {
			if (p&1) {ans *= b; ans %= mod;}
			b *= b;
			b %= mod;
		}
		return ans;
	}
	inline ll max(ll a, int b) { return (a > b ? a : b); }
	inline ll max(int a, ll b) { return (a > b ? a : b); }
	inline ll min(ll a, int b) { return (a < b ? a : b); }
	inline ll min(int a, ll b) { return (a < b ? a : b); }
	template <class T> inline bool chkmin(T&x, const T& y) { return x > y ? x = y, 1 : 0; }
	template <class T> inline bool chkmax(T&x, const T& y) { return x < y ? x = y, 1 : 0; }
}
namespace IO {
	template<class T> inline void _R(T &x) {cin >> x;}
	template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);}
	template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);}
	template<class T> inline void _R(deque<T> &x) {for (auto& i : x) _R(i);}
	inline void R() {}
	template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);}

	template<class T> inline void _W(const T& x);
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p);
	template<class... T> inline void _W(const vector<T...>& x);
	template<class... T> inline void _W(const deque<T...>& x);
	template<class... T> inline void _W(const forward_list<T...>& x);
	template<class... T> inline void _W(const list<T...>& x);
	template<class... T> inline void _W(const set<T...>& x);
	template<class... T> inline void _W(const multiset<T...>& x);
	template<class... T> inline void _W(const unordered_set<T...>& x);
	template<class... T> inline void _W(const unordered_multiset<T...>& x);
	template<class... T> inline void _W(const map<T...>& x);
	template<class... T> inline void _W(const multimap<T...>& x);
	template<class... T> inline void _W(const unordered_map<T...>& x);
	template<class... T> inline void _W(const unordered_multimap<T...>& x);

	template<class T> inline void _W(const ordered_set<T>& x);

	template<class Container> inline void printContainer(const Container& x) { bool isFirst = 1; for (auto i : x) { if (!isFirst) cout << ' '; isFirst = 0; _W(i); } }

	template<class T> inline void _W(const T& x) {cout << x;}
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);}
	template<class... T> inline void _W(const vector<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const deque<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const forward_list<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const list<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const set<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const multiset<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_set<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_multiset<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const map<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const multimap<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_map<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_multimap<T...>& x) { printContainer(x); }

	template<class T> inline void _W(const ordered_set<T>& x) { printContainer(x); }

 	inline void W() {cout << '\n';}
	template<class T> inline void W(const T &x) {_W(x); W();}
	template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);}
} using namespace IO;
namespace outputFormat{
	inline string Case(int tc) {return "Case #" + to_string(tc) + ':';}
	inline string YN(bool b) {return b ? "Yes" : "No";}
} using namespace outputFormat;
namespace std {
    template <class T1, class T2> struct hash<pair<T1,T2>> {
    	std::size_t operator()(pair<T1,T2> _) const {
        	return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
    	}
    };
}
const Mint ZERO = Mint(0, MOD998);

int main() {
	string s,t; R(s,t);
	int ls = s.length(), lt = t.length();

	vector<int> ps(ls, 0), pt(lt, 0);
	for (int i = 0; i < ls; i++) {
		ps[i] = (s[i] != 'A');
		if (i > 0)
			ps[i] += ps[i - 1];
	}

	for (int i = 0; i < lt; i++) {
		pt[i] = (t[i] != 'A');
		if (i > 0)
			pt[i] += pt[i - 1];
	}

	auto getBC = [&](vector<int>& p, int l, int r) {
		return p[r] - (l > 0 ? p[l - 1] : 0);
	};

	vector<int> cs(ls, 0), ct(lt, 0);
	for (int i = 0; i < ls; i++) {
		cs[i] = (i > 0 ? cs[i - 1] : 0) + 1;
		if (s[i] != 'A')
			cs[i] = 0;
	}

	for (int i = 0; i < lt; i++) {
		ct[i] = (i > 0 ? ct[i - 1] : 0) + 1;
		if (t[i] != 'A')
			ct[i] = 0;
	}

	CASE(Q) {
		int a,b,c,d; R(a,b,c,d); a--; b--; c--; d--;

		int x = getBC(ps,a,b), y = getBC(pt,c,d);
		int sx = cs[b], sy = ct[d];

		if (sx > sy) {
			x += 2;
		}

		_W(x <= y && sy <= sx && (y - x) % 2 == 0);
	}

	return 0;
}

static auto __init__ = [](){
#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);
#endif
	cout << fixed << setprecision(10);
	return 42;
}();

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
inline int read()
{
    int sum=0,p=1;char ch=getchar();
    while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
    if(ch=='-')p=-1,ch=getchar();
    while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
    return sum*p;
}

const int maxn=1e5+20;

char s[maxn];
int n,m,a[maxn],b[maxn],pa[maxn],pb[maxn];
char p[maxn];

void init()
{
	cin>>(s+1);
	cin>>(p+1);
	n=strlen(s+1);
	m=strlen(p+1);
	REP(i,1,n)a[i]=a[i-1]+(s[i]=='B')+(s[i]=='C');
	REP(i,1,m)b[i]=b[i-1]+(p[i]=='B')+(p[i]=='C');
	REP(i,1,n)pa[i]=s[i]=='A'?pa[i-1]+1:0;
	REP(i,1,m)pb[i]=p[i]=='A'?pb[i-1]+1:0;
}

inline void doing()
{
	int q=read();
	REP(i,1,q)
	{
		int l=read(),r=read();
		int l1=read(),r1=read();
		int x=a[r]-a[l-1],y=b[r1]-b[l1-1];
		int Pa=min(pa[r],r-l+1),Pb=min(pb[r1],r1-l1+1);
		if(x<=y && (y-x)%2==0 && Pa>=Pb && (x<y || (Pa-Pb)%3==0) && (x || y || (r-l+1==r1-l1+1) ))putchar('1');
		else putchar('0');
	}
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("E.in","r",stdin);
    freopen("E.out","w",stdout);
#endif
	init();
	doing();
	return 0;
}

// In the name of Allah.
// We're nothing and you're everything.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int maxn = 1e5 + 14;
int n, m;
struct S{
	string s;
	int n;
	int preA[maxn], cntB[maxn];
	void build(){
		for(auto &c : s)
			if(c == 'C')
				c = 'B';
		n = s.size();
		for(int i = 0; i < n; i++)
			cntB[i + 1] = cntB[i] + (s[i] == 'B');
		for(int i = 0; i < n; i++)
			if(s[i] == 'A')
				preA[i + 1] = 1 + preA[i];
	}
}  s, p;
int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> s.s >> p.s;
	s.build();
	p.build();
	int q;
	cin >> q;
	while(q--){
		int sl, sr, pl, pr;
		cin >> sl >> sr >> pl >> pr;
		sl--, pl--;
		int sb = s.cntB[sr] - s.cntB[sl];
		if(min(sr - sl, s.preA[sr]) % 3 != min(pr - pl, p.preA[pr]) % 3)
			sb += 2;
		if(min(sr - sl, s.preA[sr]) < min(pr - pl, p.preA[pr]) || sb > p.cntB[pr] - p.cntB[pl] || sb % 2 != (p.cntB[pr] - p.cntB[pl]) % 2
		   || min(sr - sl, s.preA[sr]) == sr - sl && sr - sl < pr - pl)
			cout << 0;
		else
			cout << 1;
	}
	cout << '\n';
}

#include <iostream>
using namespace std;
int la[1000002], lb[1000002], pa[1000002], pb[1000002], ka[1000002], kb[1000002];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    la[0]=-1;
    for (int i=1; i<=a.size(); i++)
    {
        if (a[i-1]!='A')
        {
            ka[i]++;
            la[i]=i;
        }
        else
            la[i]=la[i-1];
        pa[i]=pa[i-1]+ka[i];
    }
    lb[0]=-1;
    for (int i=1; i<=b.size(); i++)
    {
        if (b[i-1]!='A')
        {
            kb[i]++;
            lb[i]=i;
        }
        else
            lb[i]=lb[i-1];
        pb[i]=pb[i-1]+kb[i];
    }
    int q;
    cin >> q;
    for (int i=0; i<q; i++)
    {
        int sa, ta, sb, tb;
        cin >> sa >> ta >> sb >> tb;
        int ila=pa[ta]-pa[sa-1], ilb=pb[tb]-pb[sb-1];
        int kona=ta-la[ta], konb=tb-lb[tb], n=0;
        if (konb>kona)
            n=1;
        if (ila==0 && ilb!=0)
        {
            ila=2;
            if (kona==konb)
                n=1;
            kona=konb;
        }
        if (ila>ilb)
            n=1;
        if (ila%2!=ilb%2)
            n=1;
        if (konb%3!=kona%3 && ila==ilb)
        {
            n=1;
        }
        cout << (n^1);
    }
}

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
#define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a,value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef long long LL;
typedef pair<LL,LL> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 1000 * 100 + 47;

char AS[MAX];
char BS[MAX];

int A[MAX], B[MAX];

int get(int* A, int l, int r)
{
    int sum = A[r];
    if (l)sum -= A[l-1];
    return sum;
}

int lastZero(int* A, int l, int r)
{
    int L = l-1;
    int R = r+1;
    while(R - L > 1)
    {
        int m = (L + R) / 2;
        int s = get(A, m, r);
        if (s  == (r - m + 1))
            R = m;
        else
            L = m;
    }
    return L;
}

int solve(int l, int r, int ll, int rr)
{
    int a = lastZero(A, l, r);
    int b = lastZero(B, ll, rr);
    int c1 = (r - l + 1) - get(A, l, r);
    int c2 = (rr - ll + 1) - get(B, ll, rr);
    int ac = r - (a+1) + 1;
    int bc = rr - (b+1) + 1;

    if (ac < bc)return 0;

    ac %= 3;
    bc %= 3;
    if(ac != bc)
    {
        --ac;
        c1 += 2;
    }
    if (c1 > c2)return 0;
    return (c1 % 2) == (c2 % 2);
}

int main()
{
    //freopen("in.txt", "r", stdin);
    scanf("%s", AS);
    scanf("%s", BS);
    int n = strlen(AS);
    int m = strlen(BS);

    FOR(i, 0, n)A[i] = AS[i] == 'A';
    FOR(i, 0, m)B[i] = BS[i] == 'A';

    FOR(i, 1, n)A[i] += A[i-1];
    FOR(i, 1, m)B[i] += B[i-1];

    int q;
    scanf("%d", &q);

    FOR(i, 0, q)
    {
        int l, r, ll, rr;
        scanf("%d%d%d%d", &l, &r, &ll, &rr);
        --l, --r, --ll, --rr;
        printf("%d", solve(l, r, ll, rr));
    }
    printf("\n");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
string s,t;
char c[N];
int cs[2][N],ct[2][N],q;
int main() {
// 	freopen("input.txt","r",stdin);
	scanf(" %s",c);
	s = c;
	scanf(" %s",c);
	t = c;
	int at = 0;
	for(auto &i : s){
		at++;
		if(i == 'C' || i == 'B'){
			i = 'B';
			cs[1][at] = cs[1][at - 1] + 1;
		}
		else{
			cs[1][at] = cs[1][at - 1];
			cs[0][at] = cs[0][at - 1] + 1;
		}
	}
	at = 0;
	for(auto &i : t){
		at++;
		if(i == 'C' || i == 'B'){
			i = 'B';
			ct[1][at] = ct[1][at - 1] + 1;
		}
		else{
			ct[1][at] = ct[1][at - 1];
			ct[0][at] = ct[0][at - 1] + 1;
		}
	}
	scanf("%d",&q);
	for(int i = 0,a,b,c,d;i < q;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int difs = cs[1][b] - cs[1][a - 1];
		int dift = ct[1][d] - ct[1][c - 1];
		bool thereis = 0;
		int need = dift - difs;
		int trails = min(b - a + 1,cs[0][b]);
		int trailt = min(d - c + 1,ct[0][d]);
		if(need&1){
			printf("0");
			continue;
		}
		if(need < 0){
			printf("0");
			continue;
		}
		if(!need){
			if(trails < trailt || (trails - trailt)%3){
				printf("0");
				continue;
			}
			printf("1");
			continue;
		}
		while((trails - trailt)%3 && need && trails - 1 >= trailt){
			need-=2;
			trails--;
			thereis = 1;
		}
while(trails - 6 >= trailt && need >= 6){
need-=6;
trails-=6;
}
		if(thereis && !trailt)trails = 0;
		if((trails - trailt)%3 || trails < trailt){
			printf("0");
			continue;
		}
		thereis|=difs;
		if(!thereis && need){
			printf("0");
			continue;
		}
		printf("1");
	}
}

#include <bits/stdc++.h>
using namespace std;
// nichijou
#define REP(i,a,b) for (int i(a); i < (b); ++i)
#define RP(i,n) REP(i,0,n)
#define PER(i,a,b) for(int i((a)-1); i >= (b); --i)
#define PR(i,n) PER(i,n,0)
#define REP1(i,a,b) REP(i,a,(b)+1)
#define RP1(i,n) REP1(i,1,n)
#define PER1(i,a,b) PER(i,(a)+1,b)
#define PR1(i,n) PER1(i,n,1)
#define DO(n) RP(__i,n)
template<class T,class U>
bool cmax(T & a, const U & b) {return a < b ? a = b, 1 : 0;}
template<class T,class U>
bool cmin(T & a, const U & b) {return b < a ? a = b, 1 : 0;}

// data type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second

// STL container
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define CLR(a) (a).clear()
#define BK(a) ((a).back())
#define FT(a) ((a).front())
#define DB(a) (a).pop_back()
#define DF(a) (a).pop_front()
#define PB push_back
#define EB emplace_back

/* I gave you my heart and then you turned around. */
void _BG(const char * s) {cerr<<s<<endl;};
template<class T, class ... TT>
void _BG(const char * s,T a, TT...b)
{
	for (int c = 0; *s && (c || *s != ','); ++s) {
		cerr<<*s;
		for (char x : "([{") c += *s == x;
		for (char x : ")]}") c -= *s == x;
	}
	cerr<<" = "<<a;
	if (sizeof...(b)) {
		cerr<<", ";
        ++s;
    }
    _BG(s,b...);
}
#ifdef PR3PONY
#define BG(...) do { \
	cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
	_BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)
#else
#define BG(...)
#endif

/* Reading input is now 20% cooler! */
bool RD() {return 1;}
bool RD(char & a) {return scanf(" %c", &a) == 1;}
bool RD(char * a) {return scanf("%s", a) == 1;}
bool RD(double & a) {return scanf("%lf", &a) == 1;}
bool RD(int & a) {return scanf("%d", &a) == 1;}
bool RD(ll & a) {return scanf("%lld", &a) == 1;}

template<class T, class ... TT>
bool RD(T & a, TT & ... b) {return RD(a) && RD(b...);}

/* Do princesses dream of magic sheep? */
#define DR(T,...) T __VA_ARGS__; RD(__VA_ARGS__)
#define RI(...) DR(int,__VA_ARGS__)

/* For it's time for you to fulfill your output. */
void PT(const char & a) {putchar(a);}
void PT(char const * const & a) {fputs(a, stdout);}
void PT(const double & a) {printf("%.16f", a);}
void PT(const int & a) {printf("%d", a);}
void PT(const ll & a) {printf("%lld", a);}

/* The line will last forever! */
template<char s = ' ', char e = '\n'>
void PL() {if (e) PT(e);}
template<char s = ' ', char e = '\n', class T, class ... TT>
void PL(const T & a, const TT & ... b)
{PT(a); if (sizeof...(b) && s) PT(s); PL<s,e>(b...);}

/* Good Luck && Have Fun ! */
const int N = 1e5+987;
void read(char s[],int & n,int sa[],int sb[])
{
    RD(s);
    n=strlen(s);
    RP(i,n) {
        sa[i+1] = sa[i];
        sb[i+1] = sb[i];
        s[i] == 'A' ? sa[i+1]++ : (sb[i+1]++, sa[i+1] = 0);
    }
}
char s[N],t[N];
int sa[N], sb[N], ta[N], tb[N];
int main()
{
    int n,m;
    read(s,n,sa,sb);
    read(t,m,ta,tb);
    RI(q);
    while (q--) {
        RI(l,r,i,j);
        --l,--i;
        int al = min(sa[r], r-l);
        int ar = min(ta[j], j-i);
        int bl = sb[r] - sb[l];
        int br = tb[j] - tb[i];
        int aal = r-l - al - bl;
        int aar = j-i - ar - br;
 //       BG(al,bl,aal,ar,br,aar);
        if (al && !ar && bl < br) {
            al = 0;
            bl += 2;
        }
        while (al>ar && al%3!=ar%3)
            --al, bl += 2;
        if (br && !bl) {
            if (aal)
                --aal;
            else
                --al;
            bl = 2;
        }
        while (al>ar && al%3!=ar%3)
            --al, bl += 2;
//        BG(al,bl,aal,ar,br,aar);
        PT(bl <= br && bl%2 == br%2 && al >= ar && al%3 == ar%3);
    }
    PL();
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define fd(i,r,l) For(int i=r;i>=l;i--)
#define N 100005
using namespace std;
char s[N],t[N];
int a1[N],b1[N],a2[N],b2[N],x1,y1,x2,y2,sa,sb,ta,tb;
bool pd()
{
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	sa=min(y1-x1+1,a1[y1]);
	sb=b1[y1]-b1[x1-1];
	ta=min(y2-x2+1,a2[y2]);
	tb=b2[y2]-b2[x2-1];
	if (sb%2!=tb%2) return false;
	if (sa<ta) return false;else sa-=ta;
	if (sb>tb) return false;
	if (sb==tb && sa%3==0) return true;
	if (sb<tb && (sa || sb)) return true;
	/*if(sb>tb || sa<ta || (sb%2)!=(tb%2)) return false;
	if(sb==tb && !(sa-ta)%3) return true;
	if(sb<tb && ((sa-ta)!=0 || sb!=0) ) return true;
	return false;*/
}
int main()
{
	freopen("string.in","r",stdin);
	//freopen("string.in","w",stdout);
	scanf("%s%s",s+1,t+1);
	for(int i=1;s[i]!=0;i++)
	{
		if(s[i]=='A') a1[i]=a1[i-1]+1;
		b1[i]=b1[i-1]+(s[i]!='A');
	}
	for(int i=1;t[i]!=0;i++)
	{
		if(t[i]=='A') a2[i]=a2[i-1]+1;
		b2[i]=b2[i-1]+(t[i]!='A');
	}
	int Q;scanf("%d",&Q);
	fo(i,1,Q)
	{
		if (pd()) printf("1"); else printf("0");
	}
}

#include <bits/stdc++.h>

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 1000100;
int t[2][N];
int sz;

int fnd(int i, int x, int y, int l, int r, int idx) {
	if (x > r || y < l)
		return 0;
	if (x >= l && y <= r) {
		return t[idx][i];
	}
	return fnd(2 * i, x, (x + y) >> 1, l, r, idx) + fnd(2 * i + 1, ((x + y) >> 1) + 1, y, l, r, idx);
}

void upd(int v, int idx) {
	v += sz;
	while (v > 0) {
		t[idx][v]++;
		v >>= 1;
	}
}

bool ans[N];
int sa[N];
int ta[N];

int main () {
	//std::ios::sync_with_stdio(false);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	memset(sa, 0, sizeof(sa));
	memset(ta, 0, sizeof(ta));
	string s, t;
	getline(cin, s);
	getline(cin, t);
	sa[0] = ta[0] = 0;
	forn(i, sz(s)) {
		if (s[i] == 'A') {
			sa[i + 1] = sa[i] + 1;
	    } else {
	    	sa[i + 1] = 0;
	    }
	}
	forn(i, sz(t)) {
		if (t[i] == 'A') {
			ta[i + 1] = ta[i] + 1;
	    } else {
	    	ta[i + 1] = 0;
	    }
	}
	sz = 1;
	while (sz < max(sz(s), sz(t)))  sz <<= 1;
	forn(i, sz(s)) {
		if (s[i] == 'B' || s[i] == 'C') {
			upd(i, 0);
		}
	}
	forn(i, sz(t)) {
		if (t[i] == 'B' || t[i] == 'C') {
			upd(i, 1);
		}
	}
	int q;
	cin >> q;
	forn(i, q) {
		int l1, r1, l2, r2;
		scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
		int k1 = fnd(1, 1, sz, l1, r1, 0);
		int k2 = fnd(1, 1, sz, l2, r2, 1);
		debug(mt(k1, k2));
		if (k1 > k2 || (k1 <= k2 && ((k1 ^ k2) & 1))) {
			ans[i] = 0;
			continue;
		}
		int len1 = sa[r1], len2 = ta[r2];
		umn(len1, (r1 - l1 + 1));
		umn(len2, (r2 - l2 + 1));
		if (len1 < len2 || (len1 >= len2 && (((len1 - len2) % 3) != 0) && k1 == k2)) {
			ans[i] = 0;
			continue;
		}

		ans[i] = 1;
	}
	forn(i, q) {
		if (ans[i]) {
			printf("1");
		} else {
			printf("0");
		}
	}
	puts("");

	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <utility>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;

#define mp make_pair
#define pb push_back

/*

B -> AC -> AAB -> AAAC -> C
C -> AB -> AAC -> AAAB -> B
A -> BC -> CB -> BB -> CC
AB -> B
AC -> C
B -> AB -> BBB

conclude

B/C are the same.
A*B -> can erase arbitrary A
*B can add arbitrary A
A -> two BB
B -> BBB

 */
const int maxn = 1e5+10;
char s_str[maxn], t_str[maxn];
int q;
int s_sum[maxn], t_sum[maxn], s_last[maxn], t_last[maxn];
int s_len, t_len;
inline void init(char *str, int *s, int &len, int *last)
{
  scanf("%s", str+1);
  len = (int) strlen(str);
  last[0] = 0;
  for (int i = 1; i <= len; ++i)
    {
      s[i] = s[i-1] + (str[i] != 'A');
      if (str[i] == 'A')
	last[i] = i;
      else
	last[i] = last[i-1];
    }
}
inline bool solve()
{
  int s_l, s_r, t_l, t_r;
  scanf("%d %d %d %d", &s_l, &s_r, &t_l, &t_r);
  int s_b = s_sum[s_r] - s_sum[s_l-1];
  int t_b = t_sum[t_r] - t_sum[t_l-1];
  if (t_str[t_r] == 'A' && s_str[s_r] != 'A')
    return false;
  if (t_str[t_r] == 'A' && s_str[s_r] == 'A')
    {
      int s_a = s_r - max(s_l, s_last[s_r]) + 1;
      int t_a = t_r - max(t_l, t_last[t_r]) + 1;
      int dif_a = s_a - t_a;
      int dif_b = t_b - s_b;
      if (dif_b < 0 || dif_b % 2 == 1)
	return false;
      int consume_a = dif_b/2;
      if (dif_a < 0)
	return false;
      if (consume_a >= 0 && dif_a % 3 == 0)
	return true;
      if (consume_a >= 1 && dif_a % 3 == 1)
	return true;
      if (consume_a >= 2 && dif_a % 3 == 2)
	return true;
      return false;
    }
  if (t_str[t_r] != 'A' && s_str[s_r] == 'A')
    s_b += 2;
  int dif = t_b - s_b;
  return dif >= 0 && dif % 2 == 0;
}
int main()
{
  init(s_str, s_sum, s_len, s_last);
  init(t_str, t_sum, t_len, t_last);
  scanf("%d", &q);
  for (int kase = 1; kase <= q; ++kase)
    putchar('0' + solve());
  putchar('\n');
}

#include "bits/stdc++.h"
using namespace std;
int acc1[100005];
int acc2[100005];
int get1(int l, int r){
  int ret = acc1[r];
  if(l)ret -= acc1[l-1];
  return ret;
}
int get2(int l, int r){
  int ret = acc2[r];
  if(l)ret -= acc2[l-1];
  return ret;
}
int nxt1[100005], nxt2[100005];
int b41[100005], b42[100005];

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);
  string str1,str2;

  cin >> str1 >> str2;

  for(int i = 0; i < str1.size(); i++)if(str1[i]=='C')str1[i]='B';
  for(int i = 0; i < str2.size(); i++)if(str2[i]=='C')str2[i]='B';

  for(int i = str1.size()-1; i >= 0; i--){
    if(str1[i]=='A')
      nxt1[i] = nxt1[i+1] + 1;
  }
  for(int i = str2.size()-1; i >= 0; i--){
    if(str2[i]=='A')
      nxt2[i] = nxt2[i+1] + 1;
  }

  for(int i = 0; i < str1.size(); i++){
    if(str1[i] == 'A'){b41[i]++;
    if(i)b41[i] += b41[i-1];}
  }for(int i = 0; i < str2.size(); i++){
    if(str2[i] == 'A'){b42[i]++;
        if(i)b42[i] += b42[i-1];}
  }

  for(int i = 0; i < str1.size(); i++){
    if(i)acc1[i] = acc1[i-1];
    if(str1[i]=='B')acc1[i]++;

  }
  for(int i = 0; i < str2.size(); i++){
    if(i)acc2[i] = acc2[i-1];
    if(str2[i]=='B')acc2[i]++;

  }

  int q; cin >> q;

  while(q--){

    int l, r;
    cin >> l >> r;
    int a, b;
    cin >> a >> b;
    a--,b--;
    l--,r--;
    int x = get1(l,r);
    int y = get2(a,b);
    int tmp = b41[r];
    int tmp2 = b42[b];
    tmp = min(tmp,r-l+1);
    tmp2 = min(tmp2,b-a+1);
    if(tmp < tmp2){
      cout << 0;
      continue;
    }
    if(tmp > tmp2){
      x += 2;
    }
    if(x > y || ((y-x)&1))cout << 0;
    else cout << 1;

  }

  return 0;
}

/**
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
      AnTi-MiRaGe on Anti-Mage xD
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <memory.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define show puts("Debug")

using namespace std;

const int N = 1e5 + 5;

string a, b, ans;

int pref[3][N], pr[3][N];

main()
{
    cin >> a >> b;
    a = ' ' + a;
    b = ' ' + b;
    for (int i = 1; i < sz(a); i++)
    {
        pref[1][i] = pref[1][i - 1] + (a[i] == 'B' || a[i] == 'C');
        if (a[i] != 'A')
            pr[1][i] = 0;
        else
            pr[1][i] = pr[1][i - 1] + 1;
    }
    for (int i = 1; i < sz(b); i++)
    {
        pref[2][i] = pref[2][i - 1] + (b[i] == 'B' || b[i] == 'C');
        if (b[i] != 'A')
            pr[2][i] = 0;
        else
            pr[2][i] = pr[2][i - 1] + 1;
    }
    int q, l, r, L, R;
    cin >> q;
    while (q--)
    {
        scanf("%d%d%d%d", &l, &r, &L, &R);
        swap(l, L);
        swap(r, R);
        if ( min(r - l + 1, pr[1][r]) % 3 == 0 || min(r - l + 1, pr[1][r]) % 3 == min(pr[2][R], R - L + 1) % 3 )
        {
            if (pref[1][r] - pref[1][l - 1] == pref[2][R] - pref[2][L - 1])
                printf("1");
            else
                printf("0");
        }
        else
            printf("0");
    }
}

#include <cstdio>
#include <cstring>
using namespace std;

const int MAXN=1e5+50;

int lS,lT;
char S[MAXN],T[MAXN];
int nS[MAXN],nT[MAXN];

inline void solveSum(char str[],int sum[]){
    int len=strlen(str+1);
    sum[0]=0;
    for (int i=1;i<=len;i++){
        if (str[i]=='A') sum[i]=0; else sum[i]=1;
        sum[i]+=sum[i-1];
    }
}

inline int lenZero(int sum[],int l,int r){
    int ret=0;
    for (int i=20;i>=0;i--){
        if (r-l+1<ret+(1<<i)) continue;
        if (sum[r]-sum[r-ret-(1<<i)]==0) ret+=(1<<i);
    }
    return ret;
}

int ans[MAXN];

int main(){
    scanf("%s%s",S+1,T+1);
    solveSum(S,nS); solveSum(T,nT);
    int Q=0; scanf("%d",&Q);
    for (int i=1;i<=Q;i++){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int lS=nS[b]-nS[a-1];
        int lT=nT[d]-nT[c-1];
        int zS=lenZero(nS,a,b);
        int zT=lenZero(nT,c,d);
        if (zS==b-a+1 && zT==d-c+1){
            if (zS>=zT && (zS-zT)%3==0) ans[i]=1; else ans[i]=0;
        }else{
            if (zT>zS) ans[i]=0; else{
                b-=zT; d-=zT;
                int lS=nS[b]-nS[a-1],lT=nT[d]-nT[c-1];
                if (S[b]=='A') lS+=2;
                if (lS<=lT && (lT-lS)%2==0) ans[i]=1; else ans[i]=0;
            }
        }
    }
    for (int i=1;i<=Q;i++) printf("%d",ans[i]); printf("\n");
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e5+10;

int n,q,cnt[maxn][2],last[maxn][2],size[2];
char s[maxn],t[maxn],ans[maxn];
int32_t main(){
    scanf("%s%s%d",s,t,&q);
    size[0]=strlen(s);
    size[1]=strlen(t);
    rep(i,0,size[0]){
	if(s[i]=='A') s[i]=0;
	else s[i]=1;
	cnt[i+1][0]=cnt[i][0]+s[i];
	last[i+1][0]=s[i]?i+1:last[i][0];
    }
    rep(i,0,size[1]){
	if(t[i]=='A') t[i]=0;
	else t[i]=1;
	cnt[i+1][1]=cnt[i][1]+t[i];
	last[i+1][1]=t[i]?i+1:last[i][1];
    }
    rep(i,0,q){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	a--,c--;
	int sum1=cnt[b][0]-cnt[a][0];
	int sum2=cnt[d][1]-cnt[c][1];
	int sm1=b-(last[b][0]==0?a:last[b][0]);
	int sm2=d-(last[d][1]==0?c:last[d][1]);
	if(sum1>sum2 || (sum1%2)!=(sum2%2) || sm1<sm2){
	    ans[i]='0';
	}else{
	    if(sum1==sum2 && (sm1%3)!=(sm2%3)){
		ans[i]='0';
	    }else{
		if(sm1==sm2 && sm1==b-a && sum2>0){
		    ans[i]='0';
		}else{
		    ans[i]='1';
		}
	    }
	}
    }
    printf("%s\n",ans);
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <memory.h>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
const double pi = 3.1415926535897932384626433832795;
const double eps = 1e-12;
const int INF = 1<<30;
const LL LINF = 1ll<<60;

#define pb push_back
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define CLR(a, v) memset((a),(v),sizeof(a))
#define sqr(a) ((a)*(a))
const int BUFFER_SZ = 1 << 20;
const int MOD = 1000*1000*1000+7;

char BUFFER[BUFFER_SZ];
int gi() { int x; scanf("%d", &x); return x; }
LL gll() { LL x; scanf("%lld", &x); return x; }
VI gvi(int n) { VI a; while(n-->0) a.pb(gi()); return a;}
string gs() { scanf("%s", BUFFER); return string(BUFFER); }
template <class T> void print(vector<T> &x, string format) { format += "%c";for (int i = 0; i < x.size(); ++i) printf(format.c_str(), x[i], i+1==x.size() ? '\n' : ' '); }
// ---------------------------------------------------------- //

struct strun {
  VI rightA;
  VI SUMnotA;
  strun(string s) {
    int sum = 0;
    int a = 0;
    for (int i = 0; i < s.size(); ++i) {
      sum += s[i]!='A'?1:0;
      SUMnotA.pb(sum);
      if (s[i]!='A') a = 0;
      else ++a;
      rightA.pb(a);
    }
  }

  int getA(int l, int r) {
    return min(r-l+1, rightA[r]);
  }
  int getNA(int l, int r) {
    return SUMnotA[r] - (l>0?SUMnotA[l-1]:0);
  }
};

set<string> S;
void dfs(string s) {
  if (s.size()>10) return;
  if (S.count(s)) return;
  S.insert(s);
  for (int i = 0; i < (int)s.size()-3+1; ++i) {
    if (s[i]=='A' && s[i+1]=='A' && s[i+2]=='A') {
      dfs(s.substr(0,i) + s.substr(i+3));
    }
  }
  for (int i = 0; i < s.size(); ++i) {
    if (s[i]=='A') dfs(s.substr(0,i) + "BC" + s.substr(i+1));
    if (s[i]=='B') dfs(s.substr(0,i) + "AC" + s.substr(i+1));
    if (s[i]=='C') dfs(s.substr(0,i) + "AB" + s.substr(i+1));
  }
}

void solve() {
  string s = gs();
  string t = gs();

  strun S(s);
  strun T(t);

  int n = gi();
  for (int i = 0; i < n; ++i) {
    int a = gi()-1;
    int b = gi()-1;

    int c = gi()-1;
    int d = gi()-1;

    int a1 = S.getA(a,b);
    int a2 = T.getA(c,d);

    int b1 = S.getNA(a,b);
    int b2 = T.getNA(c,d);
    if (b1==b2) {
      if (a1%3 != a2%3) printf("0");
      else printf("1");
    } else {
      if (b1>b2) printf("0");
      else {
        if ((b2-b1)%2 || a1<a2) printf("0");
        else printf("1");
      }
    }
  }
  printf("\n");
}

int main() {
#ifdef DEAD_RABBIT
  freopen("../in.txt","r",stdin);
  //freopen("../out.txt","w",stdout);
  clock_t start = clock();
#endif
  /*
  S.clear();
  dfs("AA");
  for (string s : S) {
    if (s.size()<=3)
      printf("%s\n", s.c_str());
  }//*/

  solve();
#ifdef DEAD_RABBIT
  fprintf(stdout, "Time: %.3lf\n", 1.0*(clock()-start)/CLOCKS_PER_SEC);
#endif
  return 0;
}

#include <bits/stdc++.h>

#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define forn(i, n) fore(i, 0, n)

#define all(a) (a).begin(), (a).end()
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define mp make_pair
#define pb push_back

#define x first
#define y second

using namespace std;

template<class A, class B> ostream& operator << (ostream &out, const pair<A, B> &p) {
	return out << "(" << p.first << ", " << p.second << ")";
}

template<class A> ostream& operator << (ostream &out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i > 0)
			out << ", ";
		out << v[i];
	}
	return out << "]";
}

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

inline int gett() {
	return clock() * 1000 / CLOCKS_PER_SEC;
}

const ld EPS = 1e-9;
const int INF = int(1e9);
const li INF64 = li(INF) * INF;
const ld PI = 3.1415926535897932384626433832795;

const int N = 200 * 1000 + 555;

char s[N], t[N];
int szs, szt;

int q;
pair<pt, pt> qs[N];

inline bool read() {
	if(scanf("%s", s) != 1)
		return false;
	scanf("%s", t);

	szs = strlen(s);
	szt = strlen(t);

	scanf("%d", &q);
	forn(i, q) {
		scanf("%d%d%d%d", &qs[i].x.x, &qs[i].x.y, &qs[i].y.x, &qs[i].y.y);
		qs[i].x.x--;
		qs[i].y.x--;
	}
	return true;
}

int cnt[2][N];
int lst[2][N];

inline int getSum(int k, int l, int r) {
	return cnt[k][r] - cnt[k][l];
}

inline void solve() {
	cnt[0][0] = cnt[1][0] = 0;
	forn(i, szs)
		cnt[0][i + 1] = cnt[0][i] + (s[i] != 'A');
	forn(i, szt)
		cnt[1][i + 1] = cnt[1][i] + (t[i] != 'A');

	lst[0][0] = s[0] == 'A' ? -1 : 0;
	lst[1][0] = t[0] == 'A' ? -1 : 0;

	fore(i, 1, szs)
		lst[0][i] = s[i] == 'A' ? lst[0][i - 1] : i;
	fore(i, 1, szt)
		lst[1][i] = t[i] == 'A' ? lst[1][i - 1] : i;

	string res;
	forn(_, q) {
		pt s[2] = {qs[_].x, qs[_].y};

		int c[2] = {0, 0};
		forn(k, 2)
			c[k] = getSum(k, s[k].x, s[k].y);

		bool ok = true;
		if(c[1] < c[0])
			ok = false;
		else if((c[1] - c[0]) & 1)
			ok = false;

		int l1 = s[0].y - max(s[0].x, lst[0][s[0].y - 1] + 1);
		int l2 = s[1].y - max(s[1].x, lst[1][s[1].y - 1] + 1);

		if(l1 < l2 || (l1 - l2) % 3 != 0)
			ok = false;

		res += ok ? '1' : '0';
	}
	puts(res.c_str());
}

int main(){
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int t = gett();
#endif

	srand(time(NULL));
	cout << fixed << setprecision(10);

	while(read()) {
		solve();

#ifdef _DEBUG
		cerr << "TIME = " << gett() - t << endl;
		t = gett();
#endif
	}
	return 0;
}

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>
#include <set>
#include <string>
#include <functional>

using namespace std;

const long long maxm = 1 << 21+1;

struct SegTree {
    vector<int> f;
    int n;
    SegTree(int n): n(n), f(maxm) {};

    void build(int id, int l, int r, vector<int> &nums) {
        if (r-l < 2) {
            f[id] = nums[l];
            return;
        };

        int mid = (l+r)/2;
        build(id*2, l, mid, nums);
        build(id*2+1, mid, r, nums);
        f[id] = f[id*2]+f[id*2+1];
    };

    int query(int id, int l, int r, int x, int y) {
        if (y <= l || x >= r) return 0;
        if (l <= x && r >= y) return f[id];
        int mid = (l+r)/2;
        return query(id*2, l, mid, x, y)+query(id*2+1, mid, r, x, y);
    };
};

int find(vector<int> &pos, int val) {
    if (pos.size() == 0) return -1;

    int low = 0;
    int high = pos.size()-1;
    while (low < high) {
        if (low == high-1) {
            if (pos[high] <= val) return pos[high];
            if (pos[low] <= val ) return pos[low];
            return -1;
        };

        int mid = (low+high)/2;
        if (pos[mid] <= val)
            low = mid;
        else
            high = mid;
    };
    if (pos[low] <= val) return pos[low];
    return -1;
};

int main() {
    //freopen("947D.txt", "r", stdin);

    string s, t;
    ios::sync_with_stdio(false);

    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    s.insert(0, " ");
    t.insert(0, " ");

    vector<int> sums(n+1, 0), sumt(m+1, 0);
    vector<int> poss, post;

    for (int i = 1; i <= n; ++i)  {
        sums[i] = sums[i-1];
        if (s[i] == 'B' || s[i] == 'C') {
            poss.push_back(i);
            sums[i]++;
        }
    };

    for (int i = 1; i <= m; ++i) {
        sumt[i] = sumt[i-1];
        if (t[i] == 'B' || t[i] == 'C') {
            post.push_back(i);
            sumt[i]++;
        };
    };

    int t0;
    cin >> t0;
    for (int i0 = 1; i0 <= t0; ++i0) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        //cout << s.substr(a, b-a+1) << endl;
        //cout << t.substr(c, d-c+1) << endl;

        int l1 = b-a+1;
        int l2 = d-c+1;

        int b1 = sums[b]-sums[a-1];
        int b2 = sumt[d]-sumt[c-1];

        if (b1 > b2)  {
            printf("0");
            continue;
        };

        int last1 = find(poss, b);
        int last2 = find(post, d);

        int a1 = 0;
        int a2 = 0;

        if (last1 != -1 && last1 >= a)
            a1 = b-last1;
        else
            a1 = l1;

        if (last2 != -1 && last2 >= c)
            a2 = d-last2;
        else
            a2 = l2;

        //cout << a1 << " " << a2 << endl;

        if (a1 < a2) {
            printf("0");
            continue;
        };

        int db = b2-b1;
        if (db % 2 != 0) {
            printf("0");
            continue;
        };

        if (db == 0) {
            if ( ((a1-a2) % 3) == 0)
                printf("1");
            else
                printf("0");
        }
        else {
            if (a2 == 0)
                printf("1");
            else if (a1 > a2)
                printf("1");
            else
                printf("0");
        }
    };

    printf("\n");

}

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    string t;
    cin >> s >> t;
    for (int i=0; i < s.size(); i++){
        if (s[i] == 'C') s[i] = 'B';
    }
    for (int i=0; i<t.size(); i++){
        if (t[i] == 'C') t[i] = 'B';
    }
    int n = s.size(), m = t.size();
    int prefs[n+1], preft[m+1];
    prefs[0] = 0, preft[0] = 0;
    for (int i=0; i < n; i++){
        prefs[i+1] = prefs[i] + (s[i] =='B');
    }
    for (int i=0; i < m; i++){
        preft[i+1] = preft[i] + (t[i] == 'B');
    }
    int ls[n+1], lt[m+1];
    ls[0] = 0, lt[0] = 0;
    for (int i=0; i < n; i++){
        if (s[i] == 'B') ls[i+1] = 0;
        else ls[i+1] = ls[i] + 1;
    }
    for (int i=0; i < m; i++){
        if (t[i] == 'B') lt[i+1] = 0;
        else lt[i+1] = lt[i] + 1;
    }
    int q;
    cin >> q;
    for (int i=0; i < q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;
        int F = prefs[b+1] - prefs[a];
        int S = preft[d+1] - preft[c];
        if (F%2 != S%2){
            cout << 0;
            continue;
        }
        if (F > S){
            cout << 0;
            continue;
        }
        int A = ls[b+1], B = lt[d+1];
        A = min(A, b-a+1);
        B = min(B, d-c+1);
        if (A<B){
            cout << 0;
            continue;
        }
        if (F==0){
            if (A==B && S!=0) cout << 0;
            else cout << 1;
            continue;
        }
        else if (A%3==B%3) cout << 1;
        else {
            F += 2;
            if (F > S) cout << 0;
            else cout << 1;
        }
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define fo(i,a,b) for (i=a; i<=b; i++)
using namespace std;

const int N=100005;
int q, n, m, i, x, y, xx, yy, s0, s1, t0, t1;
char ch, s[N], t[N];
int a[N], b[N], c[N], d[N];

int main()
{
	//freopen("d.in","r",stdin); freopen("d.out","w",stdout);

	while (1)
	{
		scanf("%c",&ch);
		if (ch=='\n') break; else
		if (ch=='A') s[++n]='1'; else s[++n]='0';
	}
	//fo(i,1,n) printf("%c",s[i]); printf("\n");
	fo(i,1,n)
	{
		a[i]=a[i-1]+(s[i]=='0');
		if (s[i]=='0') b[i]=0; else b[i]=b[i-1]+1;
	}

	while (1)
	{
		scanf("%c",&ch);
		if (ch=='\n') break; else
		if (ch=='A') t[++m]='1'; else t[++m]='0';
	}
	//fo(i,1,m) printf("%c",t[i]); printf("\n");
	fo(i,1,m)
	{
		c[i]=c[i-1]+(t[i]=='0');
		if (t[i]=='0') d[i]=0; else d[i]=d[i-1]+1;
	}

	scanf("%d",&q);
	while (q)
	{
		q--, scanf("%d%d%d%d",&x,&y,&xx,&yy);
		s0=a[y]-a[x-1], t0=c[yy]-c[xx-1];
		s1=min(b[y],y-x+1), t1=min(d[yy],yy-xx+1);
		if (s0>t0) printf("0"); else
		if (s0%2!=t0%2) printf("0"); else
		if (s1<t1) printf("0"); else
		if (!s0 && t0 && s1==t1) printf("0"); else
		if (s1%3==t1%3) printf("1"); else
		if (s0==t0) printf("1"); else printf("0");
	}
}

#include <stdio.h>
#include <stack>
#include <map>
#include <string.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <climits>
#include <unordered_map>
using namespace std;
#define ll long long
#define mp make_pair
#define inf32 INT_MAX
#define inf64 LLONG_MAX
//#define ld long double
const int mod = (1e9) + 7;
const double eps = 1e-9;
const int siz = 1e5 + 5, siz2 = 1e5 + 5;
char st[2][siz];
int q, bc[2][siz], lbc[2][siz], sz[2];
int main()
{
	scanf("%s%s%d", st[0]+1, st[1]+1, &q);
	sz[0] = strlen(st[0]+1);
	sz[1] = strlen(st[1]+1);
	for (int i = 0; i < 2; i++) {
		for (int j = 1; j <= sz[i]; j++) {
			bc[i][j] = bc[i][j - 1];
			lbc[i][j] = lbc[i][j - 1];
			if(st[i][j] != 'A') {
				bc[i][j]++;
				lbc[i][j] = j;
			}
		}
	}
	vector<int> ans;
	while (q--) {
		int ai, bi, ci, di;
		scanf("%d%d%d%d", &ai, &bi, &ci, &di);
		int bc0 = bc[0][bi] - bc[0][ai - 1], bc1 = bc[1][di] - bc[1][ci-1];
		int la0 = bi - max(ai-1, lbc[0][bi]), la1 = di - max(ci-1, lbc[1][di]);
		if (bc0 == 0 && bc1 != 0) {
			la0--;
			bc0 += 2;
		}
		if (bc1 >= bc0 && (bc1 - bc0) % 2 == 0 && la0 >= la1 && ((la0-la1)%3==0 || bc1 != bc0))
			ans.push_back(1);
		else
			ans.push_back(0);
	}
	for (auto v : ans)
		printf("%d", v);
	printf("\n");
	return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 100050;

struct ABC{
  char s[N];
  int n, av[N << 2], bv[N << 2];

  inline void upd(int o, int l, int r) {
    if (l == r) {
      av[o] = s[l] == 'A';
      bv[o] = s[l] != 'A';
    } else {
      int lc = o << 1, rc = o << 1 | 1;
      bv[o] = bv[lc] + bv[rc];
      av[o] = (bv[rc] == 0 ? av[lc] : 0) + av[rc];
    }
  }

  void Build(int o, int l, int r) {
    if (l != r) {
      int mid = (l + r) >> 1;
      Build(o << 1, l, mid);
      Build(o << 1 | 1, mid + 1, r);
    }
    upd(o, l, r);
  }

  void Query(int o, int l, int r, int L, int R, int &a, int &b) {
    if (r < L || R < l) return;
    if (L <= l && r <= R) {
      a = (bv[o] == 0 ? a : 0) + av[o];
      b = b + bv[o];
    } else {
      int mid = (l + r) >> 1;
      Query(o << 1, l, mid, L, R, a, b);
      Query(o << 1 | 1, mid + 1, r, L, R, a, b);
    }
  }

  inline void Init() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    Build(1, 1, n);
  }

  inline void Query(int L, int R, int &a, int &b) {
    Query(1, 1, n, L, R, a, b);
  }
}S, T;

int main() {
  S.Init();
  T.Init();
  int m;
  scanf("%d", &m);
  while (m--) {
    int sl, sr, tl, tr;
    scanf("%d%d%d%d", &sl, &sr, &tl, &tr);
    int sa, sb, ta, tb;
    S.Query(sl, sr, sa, sb);
    T.Query(tl, tr, ta, tb);
    int ans;
    ans = sa >= ta && (sa - ta) % 3 == 0 && sb <= tb && (tb - sb) % 2 == 0;
    printf("%d", ans);
  }
  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

const int MX_SZ = 1e+5 + 42;

void process(vector<int> &a, vector<int> &b, string &s) {
    int carry = 0;
    for (int i = 1; i <= s.size(); ++i) {
        if (s[i - 1] == 'C') {
            s[i - 1] = 'B';
        }
        b[i] = b[i - 1] + (s[i - 1] == 'B');
        if (s[i - 1] == 'A') {
            ++carry;
        } else {
            carry = 0;
        }
        a[i] = carry;
    }
}

int get_a(int l, int r, vector<int> &pref, const string &s) {
    int ret = 0;
    if (pref[r] == pref[l] + (r - l)) {
        ret = pref[r] - pref[l];
        if (s[l - 1] == 'A') {
            ++ret;
        }
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    vector<int> pref_sa(MX_SZ, 0), pref_sb(MX_SZ, 0);
    vector<int> pref_ta(MX_SZ, 0), pref_tb(MX_SZ, 0);
    process(pref_sa, pref_sb, s);
    process(pref_ta, pref_tb, t);
    int q;
    cin >> q;
    int ls, rs, lt, rt;
    int a_s, a_t;
    string ans = "";
    for (int i = 0; i < q; ++i) {
        //cout << ans << endl;
        cin >> ls >> rs >> lt >> rt;
        a_s = get_a(ls, rs, pref_sa, s);
        a_t = get_a(lt, rt, pref_ta, t);
        int b_s = pref_sb[rs] - pref_sb[ls - 1];
        int b_t = pref_tb[rt] - pref_tb[lt - 1];
        if ((a_s == a_t) && ((b_s == 0) && (b_t != 0))) {
            ans+= '0';
            continue;
        }
        //cout << a_s << " " << a_t << endl;
        //cout << b_s << " " << b_t << endl;
        if (a_s < a_t) {
            ans += '0';
            continue;
        }
        if (a_s > a_t and (a_s % 3) != (a_t % 3)) {
            b_s += 2;
        }
        if (b_s <= b_t and (b_s % 2) == (b_t % 2)) {
            ans += '1';
            continue;
        } else {
            ans += '0';
            continue;
        }
    }
    cout << ans << endl;
}

#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]= jj0[i-1]+1;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i] = jj1[i-1]+1;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 = pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c2-c1)%2)
				cout<<0;
			else if(jj0[r1]<jj1[r2]||(((jj0[r1]-jj1[r2])%3)&&c1==c2)||(c1==0&&jj0[r1]==jj1[r2]))
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}
/*#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<fstream>
#include<functional>
#include<list>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
typedef unsigned long long ull;
const int N = 100000 + 5;
#define ll long long
ll dp[2005][2005];//len now
#define mod 1000000007

int main(){
ios::sync_with_stdio(false);
ull n;
int q;
ull a[65],sum[65];
a[1] = sum[1] = 1;
for(int i = 2;i<=63;i++){
a[i] = a[i-1]*2;
sum[i] = sum[i-1]+a[i];
}
while(cin>>n){
ull tmp = n-1;
int idx = 1;
while(tmp<sum[idx]) idx++;
cin>>q;
for(int i = 0;i<q;i++){
ull pos;
cin>>pos;
if(pos%2)
cout<<(pos+1)/2<<endl;
else{

}
}
}
}
*/

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define range(i,a,b) for(int i = (a);i <= (b);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
#define vi vector<int>
#define vl vector<long long>
#define vd vector<double>
#define vp vector<pair<int,int> >
#define ll long long
#define pi pair<int,int>
#define popcnt(x) __builtin_popcountll(x)
#define LSOne(x) ((x) & (-(x)))
#define xx first
#define yy second
#define PQ priority_queue
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prp(p) cerr << "(" << (p).first << " ," << (p).second << ")";
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
using namespace std;

struct node{
	int pref,suff;
	node(){
		memset(this,0,sizeof *this);
	}
	friend ostream & operator << (ostream & st,const node & u) {
		string s = "'";
		loop(i,u.pref) s += "B";
		loop(i,u.suff) s += "A";
		s += "'";
		st << s ;
		return st;
	}
};

const int MAX = 100*1000 + 10,MAXST = MAX*4;
node ST[2][MAXST];
int n,m;
char S[MAX],T[MAX];

node merge(node L,node R) {
	node ret = node();
	if(R.pref) {
		ret.pref = L.pref + R.pref;
		ret.suff = R.suff;
	}
	else {
		ret.pref = L.pref;
		ret.suff = L.suff + R.suff;
	}
//	cerr << L << " & " << R << " -> " << ret << endl;
	return ret;
}

void build(int cur,int s,int e,node ST[],char *S) {
	if(s == e) {
		ST[cur] = node();
		if(S[s] == 'A') {
			ST[cur].suff = 1;
		}
		else {
			ST[cur].pref = 1;
		}
		return;
	}
	int m = (s + e) >> 1,left = 2*cur + 1,right = left + 1;
	build(left,s,m,ST,S);
	build(right,m+1,e,ST,S);
	ST[cur] = merge(ST[left] , ST[right]);
}

node query(int cur,int s,int e,int l,int r,node *ST) {
	if(l <= s && e <= r) return ST[cur];
	int m = (s + e) >> 1,left = 2*cur + 1,right = left + 1;
	if(r <= m) return query(left,s,m,l,r,ST);
	if(m < l) return query(right,m+1,e,l,r,ST);
	return merge(query(left,s,m,l,m,ST) , query(right,m+1,e,m+1,r,ST));
}

bool are_equal(node a,node b) {
	if(a.suff < b.suff) return 0;
	int A = a.suff - b.suff;
	int k = (b.pref - a.pref);
	if(k & 1) return 0;
	k /= 2;
	k = A - k;
	if(k%3) return 0;
	k /= 3;
	return k >= 0 && k <= A/3;
}

int main(){
	#ifdef HOME
		freopen("in.in", "r", stdin);
	#endif
	scanf("%s %s",S,T);
	n = strlen(S);
	m = strlen(T);
	build(0,0,n-1,ST[0],S);
	build(0,0,m-1,ST[1],T);
	int Q; scanf("%d",&Q);
	loop(q,Q) {
		int s,e,l,r; scanf("%d %d %d %d",&s,&e,&l,&r);
		s--,e--,l--,r--;
		node a = query(0,0,n-1,s,e,ST[0]) ,b = query(0,0,m-1,l,r,ST[1]);
//		cerr << a << " vs " << b << endl;
//		cerr << canon(a) << " " << canon(b) << endl;
		bool res = are_equal(a,b);
		putchar(res + '0');
	}
	puts("");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int maxn = 100002;

string S, T;
int ps[2][maxn], _prev[2][maxn];

void init() {
    S = '@' + S;
    T = '@' + T;
    _prev[0][0] = _prev[1][0] = 1;
    for (int i=1; i<S.size(); ++i) {
        ps[0][i] = ps[0][i-1] + (S[i]!='A');
        if (S[i]=='A')
            _prev[0][i] = min(_prev[0][i-1], i);
        else _prev[0][i] = i+1;
    }
    for (int i=1; i<T.size(); ++i) {
        ps[1][i] = ps[1][i-1] + (T[i]!='A');
        if (T[i]=='A')
            _prev[1][i] = min(_prev[1][i-1], i);
        else _prev[1][i] = i+1;
    }
}

int main() {
    //freopen("pickstr.inp", "r", stdin);
    //freopen("pickstr.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> S >> T;
    init();
    int q;
    cin >> q;
    while (q--) {
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        int gs = ps[0][r1] - ps[0][l1-1];
        int gt = ps[1][r2] - ps[1][l2-1];
        int fs = r1 - max(l1, _prev[0][r1]) + 1;
        int ft = r2 - max(l2, _prev[1][r2]) + 1;
        if (gs==gt) {
            if (fs>=ft && (fs-ft)%3==0)
                cout << 1;
            else cout << 0;
        }
        else if (gs>gt) {
            cout << 0;
        }
        else if (gs<gt) {
            if ((gs-gt)%2==0 && fs>ft || (fs==ft && l1!=r1))
                cout << 1;
            else cout << 0;
        }
    }
}

//Updated 29.09.18
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <stdio.h>
#include <time.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define sqr(z) (z) * (z)
#define ch_NO(x) cout << "NO\n"; x = 1 - x;
#define b_NO cout << "NO\n"; break;
#define r_NO cout << "NO\n"; return 0;
#define c_NO cout << "NO\n"; continue;
#define ch_YES(x) cout << "YES\n"; x = 1 - x;
#define b_YES cout << "YES\n"; break;
#define r_YES cout << "YES\n"; return 0;
#define c_YES cout << "YES\n"; continue;
#define sz size()
#define pb push_back
#define int_ "%d",
#define fi first
#define se second
#define mm(k) memset((k), -1, sizeof(k));
#define all(k) (k).begin(), (k).end()
#define forn(i, n) for (int (i) = 0; (i) != (n); i++)
#define nfor(i, n) for (int (i) = (n) - 1; (i) != -1; i--)
#define do_nothing cout << " Work_Error ";
#define erace erase
#define incert insert
#define reverce reverse
#define re return
#define prev prev1234
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef double ld;
typedef pair<ll, ll> lpii;
typedef unsigned long long ull;
const int INF = 1e9;
const ll INFLL = 1e18 + 1;
const int MAX = 200001;
const ll MOD = 1000000007;
const int SZ = 300100;
const double PI = 3.14159265358979323846264338327;
ll inq(ll k, ll q, ll mod)
{
    if (q == 0)
        return 1;
    ll l = inq(k, q / 2, mod);
    if (q % 2 == 0)
        return l * l % mod;
    else
        return l * l % mod * k % mod;
}
ll gcd(ll a, ll b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll cubr(ll a)
{
    ll l = -1, r = 1e6 + 2;
    while (l < r - 1)
    {
        ll mid = (l + r) / 2;
        if (mid * mid * mid > a)
            r = mid;
        else
            l = mid;
    }
    return l;
}
ll max(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}
ll min(ll a, ll b)
{
    return -1 * max(-a, -b);
}
ll possible(ll q)
{
    if (q == INF)
        return -1;
    return q;
}
bool correct(int x, int xx)
{
    if (x < 0)
        return 0;
    if (x >= xx)
        return 0;
    return 1;
}
ll dsumm(ll x, ll k)
{
    ll y = 1;
    ll z = 0;
    for (int i = 0; y < 1e18; i++)
    {
        z += x / y % k;
        y *= k;
    }
    return z;
}
ll dcount(ll x)
{
    ll y = 1;
    ll z = 0;
    int c[100];
    for (int i = 0; i < 10; i++)
    c[i] = 0;
    for (int i = 0; x > 0; i++)
    {
        if (c[x / y % 10] == 0)
        z++;
        c[x / y % 10] = 1;
        x /= 10;
    }
    return z;
}
ll lg10(ll x)
{
    if (10000 <= x && x < 100000)
        re 5;
    if (x == 0)
        return 0;
    return lg10(x / 10) + 1;
}
ll g(ll x, ll mod)
{
    if (x == 0)
        re 0;
    return x / mod + g(x / mod, mod);
}
bool is_digit(char c)
{
    re ('0' <= c && c <= '9');
}

#define bitcount __builtin_popcount
#define bitcountl __builtin_popcountll

#define RA(n, arr) cin >> n; forn(i, n) cin >> (arr)[i];
#define WA(n, arr) cout << n << "\n"; forn(i, n) cout << (arr)[i] << " ";
#define WWA(n, arr) forn(i, n) cout << (arr)[i] << " ";
#define RSA(n, arr) cin >> n; forn(i, n) cin >> (arr)[i]; sort(arr, arr + n);
#define WSA(n, arr) cout << n << "\n"; sort(arr, arr + n); forn(i, n) cout << (arr)[i] << " ";
#define WWSA(n, arr) sort(arr, arr + n); forn(i, n) cout << (arr)[i] << " ";
#define WSV(vec) cout << vec.size() << "\n"; sort(all(vec)); forn(i, vec.sz) cout << (vec)[i] << " ";
#define WWSV(vec) sort(all(vec)); forn(i, vec.sz) cout << (vec)[i] << " ";
//string months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//vi cx, cy;
//______________________
#include <deque>
#define endl "\n"
#define int long long

string s;
string t;
ll prefAS[500000];
ll prefAT[500000];

signed main()
{
    //freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> s;
    cin >> t;
    forn(i, s.sz)
    {
        if (s[i] == 'C')
            s[i] = 'B';
        if (i > 0)
            prefAS[i] = prefAS[i - 1];
        prefAS[i] += (s[i] == 'A');
    }
    forn(i, t.sz)
    {
        if (t[i] == 'C')
            t[i] = 'B';
        if (i > 0)
            prefAT[i] = prefAT[i - 1];
        prefAT[i] += (t[i] == 'A');
    }
    ll q;
    cin >> q;
    while (q--)
    {
        ll l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        l1--;
        r1--;
        l2--;
        r2--;
        ll cntA1 = prefAS[r1] - (l1 > 0 ? prefAS[l1 - 1] : 0);
        ll cntA2 = prefAT[r2] - (l2 > 0 ? prefAT[l2 - 1] : 0);
        ll cntT1 = r1 - l1 + 1 - cntA1;
        ll cntT2 = r2 - l2 + 1 - cntA2;
        cout << cntA1 << " " << cntA2 << " " << cntT1 << " " << cntT2 << endl;
        if (cntT1 % 2 != cntT2 % 2)
        {
            cout << 0 << endl;
        }
    }
}

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 1e5 + 7;

int x[N];
int y[N];

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = (int) s.size(), m = (int) t.size();
	vector<int> ps(n + 1), pt(m + 1);
	for (int i = 0; i < n; ++i)
		ps[i + 1] = ps[i] + int(s[i] == 'A');
	for (int i = 0; i < m; ++i)
		pt[i + 1] = pt[i] + int(t[i] == 'A');
    for (int i = 0; i < n; i++)
    {
        if (i != 0) x[i] = x[i - 1];
        if (s[i] != 'A')
        {
            x[i]++;
        }
    }
    for (int i = 0; i < m; i++)
    {
        if (i != 0) y[i] = y[i - 1];
        if (t[i] != 'A')
        {
            y[i]++;
        }
    }
    int q;
    cin >> q;
    while (q--)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;
        int l = x[b] - (a ? x[a - 1] : 0);
        int r = y[d] - (c ? y[c - 1] : 0);
		bool ok = true;
        if (l == 0)
        {
            if (b - a + 1 == d - c + 1 && r == 0)
            {
                cout << 1;
                continue;
            }
            else
            {
                l += 2;
            }
        }
        if (l <= r && l % 2 == r % 2)
        {
			ok = true;
        }
        else
        {
			ok = false;
        }
		int L = a - 1, R = b + 1;
		while (R - L > 1)
		{
			int M = (L + R) / 2;
			if (ps[b + 1] - ps[M] == b + 1 - M)
				R = M;
			else
				L = M;
		}
		int la = b + 1 - R;
		L = c - 1, R = d + 1;
		while (R - L > 1)
		{
			int M = (L + R) / 2;
			if (pt[d + 1] - pt[M] == d + 1 - M)
				R = M;
			else
				L = M;
		}
		int ra = d + 1 - R;
		cerr << la << ' ' << ra << '\n';
		if (l < r)
			ok &= la >= ra;
		else
			ok &= la >= ra && la % 3 == ra % 3;
		cout << ok;
    }
    cout << '\n';
}

#include <queue>
#include <random>
#include <limits>
#include <assert.h>
#include <time.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <string>
#include <set>
#include <map>
using namespace std;
#define forn(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define whats(a) cerr<<#a<<" "<<a<<endl;
#define Mod(a,b) (((a)%(b)+(b))%(b))
#define sz(x) (int((x).size()))
typedef long long ll;
typedef int Int;
//#define int ll

typedef vector<int> vec;
typedef vector<vec> mat;

const int N = (int)1e6 + 3;

vector<string> ApplyRule(string from, string to, string s) {
    vector < string > res;
    int start = 0;
    for (;;) {
        int where = s.find(from, start);
        if (where == string::npos) break;

        string nxt;
        if (where - 1 >= 0) nxt += s.substr(0, where);
        nxt += to;
        if (where + sz(from) < sz(s)) nxt += s.substr(where + sz(from));
        res.push_back(nxt);

        start = where + 1;
    }
    return res;
}

void AllDerivations(string start) {
    queue<string> q;
    q.push(start);
    map<string, string> prev;
    prev[start] = 'z';

    int max_len = 10;
    for (; !q.empty();) {
        string now = q.front();
        q.pop();

        if (sz(now) <= 2) {
            if (now.find("C") == -1) {
                vector<string> path;
                string v = now;
                for (; v != "z"; v= prev[v]) {
                    path.push_back(v);
                }
                reverse(path.begin(), path.end());

                bool first = true;
                for (auto & p : path) {
                    if (first)first = false;
                    else cout << " -> ";
                    cout << p;
                }
                cout << endl;
            }
        }

        vector<string> neigh;
        neigh = ApplyRule("A", "BC", now);
        for (auto n : neigh) {
            if (sz(n) > max_len) continue;
            if (prev.count(n))continue;
            prev[n] = now;
            q.push(n);
        }

        neigh = ApplyRule("B", "AC", now);
        for (auto n : neigh) {
            if (sz(n) > max_len) continue;
            if (prev.count(n))continue;
            prev[n] = now;
            q.push(n);
        }

        neigh = ApplyRule("C", "AB", now);
        for (auto n : neigh) {
            if (sz(n) > max_len) continue;
            if (prev.count(n))continue;
            prev[n] = now;
            q.push(n);
        }

        neigh = ApplyRule("AAA", "", now);
        for (auto n : neigh) {
            if (sz(n) > max_len) continue;
            if (prev.count(n))continue;
            prev[n] = now;
            q.push(n);
        }
    }
}

int Sum(vec &a, int l, int r) {
    return a[1 + r] - a[1 + l - 1];
}

Int main(Int argc, char * argv[])
{
#ifdef Home
    freopen("inp.txt", "rb", stdin);
#endif
    ios::sync_with_stdio(0);

    string S, T;
    cin >> S >> T;
    int n = sz(S);
    int m = sz(T);
    forn(i, 0, n) {
        if (S[i] == 'C')S[i] = 'B';
    }

    forn(i, 0, m) {
        if (T[i] == 'C')T[i] = 'B';
    }

    vec SA(n+1),SB(n+1),TA(m+1),TB(m+1);
    vec STrail(n + 1);
    vec TTrail(m + 1);

    forn(i, 0, n) {
        SA[1 + i] = SA[1 + i - 1] + (S[i] == 'A');
        SB[1 + i] = SB[1 + i - 1] + (S[i] == 'B');
        if (S[i] == 'A') {
            STrail[1 + i] = STrail[1 + i - 1] + 1;
        } else {
            STrail[1 + i] = 0;
        }
    }
    forn(i, 0, m) {
        TA[1 + i] = TA[1 + i - 1] + (T[i] == 'A');
        TB[1 + i] = TB[1 + i - 1] + (T[i] == 'B');
        if (T[i] == 'A') {
            TTrail[1 + i] = TTrail[1 + i - 1] + 1;
        } else {
            TTrail[1 + i] = 0;
        }
    }

    int q;
    cin >> q;
    forn(i, 0, q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--;
        b--;
        c--;
        d--;

        int Bs = Sum(SB, a, b);
        int Bt = Sum(TB, c, d);
        int trail_s = min(b - a + 1, STrail[1 + b]);
        int trail_t = min(d - c + 1, TTrail[1 + d]);

        if (Bs%2 == Bt%2) {
            if (trail_t > trail_s) {
                cout << 0;
            } else if ((trail_t - trail_s) % 3 == 0) {
                cout << 1;
            } else {
                cout << 0;
            }
            continue;
        }

        if (trail_s == trail_t) {
            if (Bs > 0) {
                cout << 1;
            } else {
                cout << 0;
            }
            continue;
        }

        if (trail_s > trail_t) {
            cout << 0;
            continue;
        }

        cout << 0;
    }

    return 0;
}

//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s,t;cin>>s>>t;
  ll n=s.size(),m=t.size();
  vector<ll>vs(n+1),vt(m+1);
  rep(i,0,n)vs[i+1]=vs[i]+(s[i]!='A');
  rep(i,0,m)vt[i+1]=vt[i]+(t[i]!='A');
  vector<ll>ps(n),pt(m);
  {
    ll pre=-1;
    rep(i,0,n){
      if(s[i]!='A')pre=i;
      ps[i]=pre;
    }
    pre=-1;
    rep(i,0,m){
      if(t[i]!='A')pre=i;
      pt[i]=pre;
    }
  }
  //debug(ps,n);
  ll q;cin>>q;
  string ret;
  while(q--){
    ll a,b,c,d;cin>>a>>b>>c>>d;a--;b--;c--;d--;
    ll xs=vs[b+1]-vs[a],xt=vt[d+1]-vt[c];
    ll rs=b-max(a-1,ps[b]),rt=d-max(c-1,pt[d]);
    //cout<<xs spa xt spa rs spa rt<<endl;
    bool sw=true;
    if(xs>xt||xs%2!=xt%2)sw=false;
    if(rs<rt)sw=false;
    if(xs==xt&&rs%3!=rt%3)sw=false;
    ret+=char('0'+sw);
  }
  cout<<ret<<endl;
  return 0;
}

#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <tuple>

using namespace std;
typedef long long ll;

#define endl "\n"
#define INF 100000000
#define MOD 1000000009

int Q, N, M, K, L;

char A[100001], B[100001];

int main() {

  cin >> A >> B >> Q;

  N = strlen(A);
  M = strlen(B);
  vector<int> ret;
  for (int q = 0; q < Q; q++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--; b--; c--; d--;

    int a1 = 0, b1 = 0, a2 = 0, b2 = 0;
    int aa1 = 0, aa2 = 0;
    for (int i = a; i <= b; i++) {
      if (A[i] == 'A') a1++;
      if (A[i] == 'B' || A[i] == 'C') b1++;
    }
    for (int i = b; i >= a; i--) {
      if (A[i] == 'A') aa1++;
      else break;
    }
    for (int i = c; i <= d; i++) {
      if (B[i] == 'A') a2++;
      if (B[i] == 'B' || B[i] == 'C') b2++;
    }
    for (int i = d; i >= c; i--) {
      if (B[i] == 'A') aa2++;
      else break;
    }
    if (b1 <= b2 && b1 % 2 == b2 % 2 && aa1 == aa2) ret.push_back(1);
    else ret.push_back(0);
  }
  for (auto i : ret) cout << i;
  cin >> N;
}

#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long

#define f first
#define s second

#define endl '\n'
#define pii pair <ll, ll>

#define ios ios_base::sync_with_stdio(0), cin.tie()
#define pb push_back
#define mp make_pair

#define pi 3.14159265358979323846264
#define y1 abacaba

#define fn "abc"

using namespace std;

const int MXN = 5e5 + 30;
const int MAXN = 1e3 + 2;
const ll INF = 1e9 + 7;
const ll BINF = 1e15;
const int mod = 1e9 + 7;
const ld EPS = 1e-15;
const ll dx[] = {0, 0, 1, -1};
const ll dy[] = {1, -1, 0, 0};

int n, m;

string a;
string b;

int pref[MXN];
int pref1[MXN];

int cnt[MXN];
int cnt1[MXN];

int q, l, r, l1, r1;

string ans;

int main(){
    #ifdef DIAS
        freopen("input.txt", "r", stdin);
    #elif NAME
    	freopen(fn".in", "r", stdin);
    	freopen(fn".out", "w", stdout);
    #endif
    cin >> a >> b;
    n = a.size();
    a = '^' + a;
    m = b.size();
    b = '^' + b;
    for(int i = 1; i <= n; i++){
    	pref[i] = pref[i - 1];
    	if(a[i] == 'A'){
    		pref[i] ++;
    		cnt[i] = cnt[i - 1] + 1;
    	}
    }
    for(int i = 1; i <= m; i++){
    	pref1[i] = pref1[i - 1];
    	if(b[i] == 'A'){
    		pref1[i] ++;
    		cnt1[i] = cnt1[i - 1] + 1;
    	}
    }
    cin >> q;
    for(int i = 1; i <= q; i++){
    	cin >> l >> r >> l1 >> r1;
    	int res = (r - l + 1) - (pref[r] - pref[l - 1]);
    	int sum = (r1 - l1 + 1) - (pref1[r1] - pref1[l1 - 1]);

    	int z1 = min(cnt[r], r - l + 1);
    	int z2 = min(cnt1[r1], r1 - l1 + 1);

    	if(z2 > z1){
    		ans += '0';
    		continue;
    	}

    	if(z1 == r - l + 1){
    		if(z2 == r1 - l1 + 1){
    			if((z1 - z2) % 3 == 0){
    				ans += '1';
    			}
    			else{
    				ans += '0';
    			}
    		} else{
    			ans += '0';
    		}
    		continue;
    	}

    	if((z1 - z2) % 3 != 0) res += 2;

    	if(res <= sum && abs(res - sum) % 2 == 0){
    		ans += '1';
    	}
    	else{
    		ans += '0';
    	}
    }
    cout << ans;
    return 0;
}

#include <iostream>
using namespace std;
int pa[2][200000];
int pb[2][200000];
void calc(string a, int at){
	for(int i=0,cnt=0,cb=0;i<a.length();++i){
		cb+=a[i]!='A';
		if(a[i]=='A')++cnt;
		else cnt=0;
		pa[at][i+1]=cnt;
		pb[at][i+1]=cb;
	}
}
int main() {
	string sa,sb;
	cin>>sa>>sb;
	calc(sa,0);
	calc(sb,1);
	int q;
	cin>>q;
	while(q--){
		int a,b,x,y;
		cin>>a>>b>>x>>y;
		int nb0=pb[0][b]-pb[0][a-1];
		int na0=min(pa[0][b],b-a+1);
		int nb1=pb[1][y]-pb[1][x-1];
		int na1=min(pa[1][y],y-x+1);
		bool ans=true;
		if(na0<na1) ans=false;
		if(na0>=na1&&na0%3!=na1%3) nb0+=2;
		if(!(nb0<=nb1&&nb0%2==nb1%2)) ans=false;
		cout<<(int)ans;
	}
}

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

int Scnt[100005][3];
int Tcnt[100005][3];
int SlastnonA[100005];
int TlastnonA[100005];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin >> s >> t;
	Scnt[1][s.at(0)-'A']++;
	SlastnonA[1] = -1;
	Tcnt[1][t.at(0)-'A']++;
	TlastnonA[1] = -1;
	for(int i = 1; i < s.length(); i++) {
		Scnt[i+1][0] = Scnt[i][0];
		Scnt[i+1][1] = Scnt[i][1];
		Scnt[i+1][2] = Scnt[i][2];
		SlastnonA[i+1] = SlastnonA[i];
		Scnt[i+1][s.at(i)-'A']++;
		if(s.at(i) != 'A') {
			SlastnonA[i+1] = i+1;
		}
	}
	for(int i = 1; i < t.length(); i++) {
		Tcnt[i+1][0] = Tcnt[i][0];
		Tcnt[i+1][1] = Tcnt[i][1];
		Tcnt[i+1][2] = Tcnt[i][2];
		TlastnonA[i+1] = TlastnonA[i];
		Tcnt[i+1][t.at(i)-'A']++;
		if(t.at(i) != 'A') {
			TlastnonA[i+1] = i+1;
		}
	}
	int q;
	cin >> q;
	for(int i = 0; i < q; i++) {
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		int sum1 = Scnt[b][1]+Scnt[b][2]-Scnt[a-1][1]-Scnt[a-1][2];
		int sum2 = Tcnt[d][1]+Tcnt[d][2]-Tcnt[c-1][1]-Tcnt[c-1][2];
		//cout << sum1 << " " << sum2 << endl;
		if(sum1 <= sum2 && (sum2-sum1)%2 == 0 && (sum2 != 0 || ((d-c)%3 == (b-a)%3 && d-c <= b-a))) {
			int lasts = SlastnonA[b];
			int lastt = TlastnonA[d];
			if(lastt == d) {
				cout << 1;
			} else {
				if(sum1 < sum2) {
					if(d-lastt <= b-lasts) {
						cout << 1;
					} else {
						cout << 0;
					}
				} else {
					if(lastt < c || ((d-lastt)%3 == (b-lasts)%3 && d-lastt <= b-lasts)) {
						cout << 1;
					} else {
						cout << 0;
					}
				}
			}
		} else {
			cout << 0;
		}
	}
	return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <memory.h>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
const double pi = 3.1415926535897932384626433832795;
const double eps = 1e-12;
const int INF = 1<<30;
const LL LINF = 1ll<<60;

#define pb push_back
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define CLR(a, v) memset((a),(v),sizeof(a))
#define sqr(a) ((a)*(a))
const int BUFFER_SZ = 1 << 20;
const int MOD = 1000*1000*1000+7;

char BUFFER[BUFFER_SZ];
int gi() { int x; scanf("%d", &x); return x; }
LL gll() { LL x; scanf("%lld", &x); return x; }
VI gvi(int n) { VI a; while(n-->0) a.pb(gi()); return a;}
string gs() { scanf("%s", BUFFER); return string(BUFFER); }
template <class T> void print(vector<T> &x, string format) { format += "%c";for (int i = 0; i < x.size(); ++i) printf(format.c_str(), x[i], i+1==x.size() ? '\n' : ' '); }
// ---------------------------------------------------------- //

struct strun {
  VI rightA;
  VI SUMnotA;
  strun(string s) {
    int sum = 0;
    int a = 0;
    for (int i = 0; i < s.size(); ++i) {
      sum += s[i]!='A'?1:0;
      SUMnotA.pb(sum);
      if (s[i]!='A') a = 0;
      else ++a;
      rightA.pb(a);
    }
  }

  int getA(int l, int r) {
    return min(r-l+1, rightA[r]);
  }
  int getNA(int l, int r) {
    return SUMnotA[r] - (l>0?SUMnotA[l-1]:0);
  }
};

set<string> S;
void dfs(string s) {
  if (s.size()>10) return;
  if (S.count(s)) return;
  S.insert(s);
  for (int i = 0; i < (int)s.size()-3+1; ++i) {
    if (s[i]=='A' && s[i+1]=='A' && s[i+2]=='A') {
      dfs(s.substr(0,i) + s.substr(i+3));
    }
  }
  for (int i = 0; i < s.size(); ++i) {
    if (s[i]=='A') dfs(s.substr(0,i) + "BC" + s.substr(i+1));
    if (s[i]=='B') dfs(s.substr(0,i) + "AC" + s.substr(i+1));
    if (s[i]=='C') dfs(s.substr(0,i) + "AB" + s.substr(i+1));
  }
}

void solve() {
  string s = gs();
  string t = gs();

  strun S(s);
  strun T(t);

  int n = gi();
  for (int i = 0; i < n; ++i) {
    int a = gi()-1;
    int b = gi()-1;

    int c = gi()-1;
    int d = gi()-1;

    int a1 = S.getA(a,b);
    int a2 = T.getA(c,d);

    int b1 = S.getNA(a,b);
    int b2 = T.getNA(c,d);
    if (b1==b2) {
      if (a1%3 != a2%3) printf("0");
      else printf("1");
    } else {
      if (b1>b2) printf("0");
      else {
        if ((b2-b1)%2) printf("0");
        else printf("1");
      }
    }
  }
  printf("\n");
}

int main() {
#ifdef DEAD_RABBIT
  freopen("../in.txt","r",stdin);
  //freopen("../out.txt","w",stdout);
  clock_t start = clock();
#endif
  /*
  S.clear();
  dfs("AA");
  for (string s : S) {
    if (s.size()<=3)
      printf("%s\n", s.c_str());
  }//*/

  solve();
#ifdef DEAD_RABBIT
  fprintf(stdout, "Time: %.3lf\n", 1.0*(clock()-start)/CLOCKS_PER_SEC);
#endif
  return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<utility>
#include<algorithm>
#include<utility>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<map>
#define P pair<int,int>
#define ll long long
#define INF 100000000
#define M 1000000007
#define MAX 100010
using namespace std;

string s, t;
int n;
int a[MAX], b[MAX];
int at[MAX], bt[MAX];

int main()
{
	cin >> s >> t;
	cin >> n;
	int ss = s.length(), tt = t.length();
	for (int i = 0; i < ss; i++) {
		if (s[i] == 'A')a[i]++;
		else b[i]++;
	}
	for (int i = 0; i < tt; i++) {
		if (t[i] == 'A')at[i]++;
		else bt[i]++;
	}
	for (int i = 1; i < ss; i++)
		a[i] += a[i - 1];
	for (int i = 1; i < ss; i++)
		b[i] += b[i - 1];
	for (int i = 1; i < tt; i++)
		at[i] += at[i - 1];
	for (int i = 1; i < tt; i++)
		bt[i] += bt[i - 1];

	int xs, ys, xt, yt;
	int sa, sb, ta, tb;
	for (int i = 0; i < n; i++) {
		cin >> xs >> ys >> xt >> yt;
		xs--; ys--; xt--; yt--;
		if (xs == 0) {
			sa = a[ys];
			sb = b[ys];
		}
		else {
			sa = a[ys] - a[xs - 1];
			sb = b[ys] - b[xs - 1];
		}
		if (xt == 0) {
			ta = at[yt];
			tb = bt[yt];
		}
		else {
			ta = at[yt] - at[xt - 1];
			tb = bt[yt] - bt[xt - 1];
		}
		if (sb == 0 && tb == 0) {
			if (sa == ta)cout << 1;
			else cout << 0; continue;
		}
		if (sb > tb) {
			cout << 0; continue;
		}
		if ((tb - sb) % 2 == 0)
			cout << 1;
		else cout << 0;
	}
	cout << endl;
	return 0;
}

# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)&1)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a); i<=(b); ++i)
#define per(i,a,b) for (int i=(a); i>=(b); --i)
#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define ____ puts("\n_______________\n\n")
#define debug(x) ____; cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) ____; cout<<#x<<":\n"; rep(i,0,n) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define debug_arr2(x,n,m) ____; cout<<#x<<":\n"; rep(i,0,n) rep(j,0,m) cout<<#x<<"["<<(i)<<"]["<<(j)<<"]= "<<x[i][j]<<((j==m)?"\n\n":"    ")
#define debug_set(x) ____; cout<<#x<<": \n"; rep_it(it,x) cout<<(*it)<<" "; cout<<endl
#define debug_map(x) ____; cout<<#x<<": \n"; rep_it(it,x) debug_pair(*it)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const ll ooo=9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N=101005;
const double PI=acos(-1.0);
const double eps=1e-9;
int o(int x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

struct ttype{
	int f[N],s[N],a[N],n,t;
	void init(char *st) {
		n=strlen(st+1),f[0]=s[0]=a[0]=t=0;
		rep(i,1,n) a[i]=(st[i]!='A'),s[i]=s[i-1]+a[i];
		rep(i,1,n) { if (a[i]) t=i; f[i]=t; }
	}
	void Q(int l,int r,int &x,int &y) { y=r-max(l-1,f[r]),x=s[r]-s[l-1]; }
} S,T;

char st[N]; int l,r,t,x,y,x_,y_,m;

int main() {
    //file_put();

    scanf("%s",st+1),S.init(st);
    scanf("%s",st+1),T.init(st);
    scanf("%d",&m);
    while (m--) {
    	scanf("%d%d",&l,&r),S.Q(l,r,x,y);
    	scanf("%d%d",&l,&r),T.Q(l,r,x_,y_);
    	t=x+(y-y_)%3*2;
    	printf("%c",'0'+(y>=y_ && t<=x_ && odd(t)==odd(x_)));
	}
	printf("\n");

    return 0;
}

//
//  main.cpp
//  VK Cup 2018 - Round 1 D
//
//  Created by Songjy on 18/6/5.
//  Copyright © 2018年 Songyj. All rights reserved.
//

#include <bits/stdc++.h>

using namespace std;

const int maxn=1e5+10;

int ssna[maxn],spa[maxn];
int tsna[maxn],tpa[maxn];

int main(int argc, const char * argv[]) {

    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    int n;
    cin>>n;
    s='.'+s;
    t='.'+t;
    for (int i=1; i<s.size(); ++i) {
        if (s[i]=='A') {
            spa[i]=spa[i-1]+1;
        }else ssna[i]=ssna[i-1]+1;
    }
    for (int i=1; i<t.size(); ++i) {
        if (t[i]=='A') {
            tpa[i]=tpa[i-1]+1;
        }else tsna[i]=tsna[i-1]+1;
    }
    int spl,tpl;
    for (int i=0; i<n; ++i) {
        int a,b,c,d;
        bool is=0;
        cin>>a>>b>>c>>d;

        if (spa[b]>=b-a+1) {
            spl=b-a+1;
        }else spl=spa[b];
        if (tpa[d]>=d-c+1) {
            tpl=d-c+1;
        }else tpl=tpa[d];

        if(spl==b-a+1&&tpl==d-c+1){
            if (spl>=tpl&&(spl-tpl)%3==0) {
                is=1;
            }
        }
        else if (spl>=tpl){
            int sna=ssna[b-tpl]-ssna[a-1];
            int tna=tsna[d-tpl]-tsna[c-1];
            if (sna>=tna) {
                if (sna==tna) {
                    if (s[b-tpl]!='A') {
                        is=1;
                    }
                }else{
                    if ((sna-tna)%2==0) {
                        is=1;
                    }
                }

            }
        }

        if (is) {
            cout<<1;
        }else
            cout<<0;

    }
    cout<<endl;
    return 0;
}

#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <tuple>

using namespace std;
typedef long long ll;

#define endl "\n"
#define INF 100000000
#define MOD 1000000009

int Q, N, M, K, L;

char A[100001], B[100001];
int a1[100001], a2[100001], b1[100001], b2[100001];
int aa1[100001], aa2[100001];

int main() {

  A[0] = B[0] = '0';

  cin >> A + 1 >> B + 1 >> Q;

  N = strlen(A);
  M = strlen(B);
  vector<int> ret;

  for (int i = 1; i < N; i++) {
    a1[i] = a1[i - 1] + (A[i] == 'A');
    b1[i] = b1[i - 1] + (A[i] == 'B' || A[i] == 'C');
    if (A[i] == 'A') aa1[i] = aa1[i - 1] + 1;
    else aa1[i] = 0;
  }
  for (int i = 1; i < M; i++) {
    a2[i] = a2[i - 1] + (B[i] == 'A');
    b2[i] = b2[i - 1] + (B[i] == 'B' || B[i] == 'C');
    if (B[i] == 'A') aa2[i] = aa2[i - 1] + 1;
    else aa2[i] = 0;
  }

  for (int q = 0; q < Q; q++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int ca1 = a1[b] - a1[a - 1];
    int cb1 = b1[b] - b1[a - 1];
    int caa1 = aa1[b];
    int ca2 = a2[d] - a2[c - 1];
    int cb2 = b2[d] - b2[c - 1];
    int caa2 = aa2[d];

    if (caa1 > (b - a + 1)) caa1 = aa1[b] - aa1[a - 1];
    if (caa2 > (d - c + 1)) caa2 = aa2[d] - aa2[c - 1];
    if (cb1 <= cb2 && cb1 % 2 == cb2 % 2 && caa1 >= caa2) {
      if (caa1 % 3 != caa2 % 3 && cb1 + 2 > cb2) ret.push_back(0);
      else ret.push_back(1);
    }
    else ret.push_back(0);
  }
  for (auto i : ret) cout << i;
  cin >> N;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,char middle=' '){
    for(int i=0;i<vec_s.size();i++)printf("%d%c",vec_s[i],(i!=vec_s.size()-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,char middle=' '){
    for(int i=0;i<vec_s.size();i++)printf("%lld%c",vec_s[i],(i!=vec_s.size()-1?middle:'\n'));
}

int bc[2][100005];
int fa[2][100005];

string sa;
bool s[100005];

int main(){
    int n,m;
    int i,j,k;
    int a,b,c,d;
    int p,q,r;
    for(i=0;i<2;i++){
        cin>>sa;
        for(j=0;j<sa.size();j++){
            bc[i][j+1]=bc[i][j];
            if(sa[j]!='A')bc[i][j+1]++;
        }
        for(j=0;j<sa.size();j++){
            if(sa[j]=='A')fa[i][j+1]=fa[i][j]+1;
        }
    }
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b>>c>>d;
        p=(bc[1][d]-bc[1][c-1])-(bc[0][b]-bc[0][a-1]);
        if(p<0 || p%2!=0){
            s[i]=false;
            continue;
        }
        q=min(fa[0][b],b-a+1)-min(fa[1][d],d-c+1);
        if(fa[0][b]>=b-a+1 && p>0)p-=2,q--;
        if(p==0 && q>=0 && q%3==0)s[i]=true;
        else if(p>0 && q>=0)s[i]=true;
        else s[i]=false;
    }
    for(i=0;i<n;i++){
        if(s[i])cout<<1;
        else cout<<0;
    }
    cout<<endl;
}

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-12;
const int N=100000+10,maxn=2000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

char s[N],p[N];
int sums[N],sump[N];
int lens,lenp;
int cal(int l,int r,int op)
{
    int tel=l-1,ter=r+1;
    while(tel<ter-1)
    {
        int m=(tel+ter)>>1;
        if(op==1)
        {
            if(sums[m]-sums[r+1]>=r-m+1)ter=m;
            else tel=m;
        }
        else
        {
            if(sump[m]-sump[r+1]>=r-m+1)ter=m;
            else tel=m;
        }
    }
    return tel;
}
bool solve(int l1,int r1,int l2,int r2)
{
    int cnta1,cnta2,cntb1,cntb2;
    cntb1=sums[l1]-sums[r1+1];
    cnta1=(r1-l1+1)-cntb1;

    if(s[r1]=='A')
        cnta1--,cntb1+=2;

    cntb2=sump[l2]-sump[r2+1];
    cnta2=(r2-l2+1)-cntb2;

    if(p[r2]=='A')
        cnta2--,cntb2+=2;

    if((cntb1+cntb2)&1)
        return false;

    if(cntb1<=cntb2)
    {
        if(cntb1+cnta1*2>=cntb2)
            return true;
        return false;
    }
    else
    {
        if(cntb2+cnta2*2>=cntb1)
            return true;
        return false;
    }
}
int main()
{
    scanf("%s%s",s+1,p+1);
    lens=strlen(s+1),lenp=strlen(p+1);
    for(int i=lens;i>=0;i--)
    {
        if(s[i]!='A')sums[i]=sums[i+1]+1;
        else sums[i]=sums[i+1];
    }
    for(int i=lenp;i>=0;i--)
    {
        if(p[i]!='A')sump[i]=sump[i+1]+1;
        else sump[i]=sump[i+1];
    }
//    printf("%d\n",cal(1,7,1));
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int l1,r1,l2,r2;
        scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
        if(solve(l1,r1,l2,r2))printf("1");
        else printf("0");
    }
    puts("");
    return 0;
}
/********************

********************/

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <random>
#include <climits>
#include <cstdio>
#include <ctype.h>
#include <time.h>
using namespace std;

#define PI acos(-1.0)
#define EPS 1e-8
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
#define go(i, a, b) for(int i = a; i <= b; ++i)
#define gorev(i, a, b) for(int i = a; i >= b; --i)

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
    return os << "(" << P.fi << "," << P.se << ")";
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
    os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, map<L, R> M){
    os << "["; for (auto pr: M) os << pr.fi << "->" << pr.se << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, unordered_map<L, R> M){
    os << "["; for (auto pr: M) os << pr.fi << "->" << pr.se << ","; return os << "]";
}

mt19937_64 mt(time(0));

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {1, 0, a};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[1], tmp[0] - (a / b) * tmp[1], tmp[2]};
    }
}

Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

/******************************** template ********************************/
#define N 100010
string s, t;
int cnt[2][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef ZYC_LOCAL
    freopen("input.txt", "rt", stdin);
#endif
    cin >> s >> t;
    for (int i = 0; i < s.length(); ++i) if (s[i] == 'C') s[i] = 'B';
    for (int i = 0; i < t.length(); ++i) if (t[i] == 'C') t[i] = 'B';
    go(i, 0, s.length() - 1) {
        if (!i) {
            cnt[0][i] = (s[i] == 'B' ? 1 : 0);
        } else {
            cnt[0][i] = cnt[0][i - 1] + (s[i] == 'B' ? 1 : 0);
        }
    }

    go(i, 0, t.length() - 1) {
        if (!i) {
            cnt[1][i] = (t[i] == 'B' ? 1 : 0);
        } else {
            cnt[1][i] = cnt[1][i - 1] + (t[i] == 'B' ? 1 : 0);
        }
    }

    int q;
    cin >> q;
    int a, b, c, d;
    string res;
    while (q--) {
        cin >> a >> b >> c >> d;
        --a;
        --b;
        --c;
        --d;
        int foo = a ? cnt[0][b] - cnt[0][a - 1] : cnt[0][b];
        int bar = c ? cnt[1][d] - cnt[1][c - 1] : cnt[1][d];
        if (foo > bar || (bar - foo) % 2 != 0) {
            res.pb('0');
        } else {
            res.pb('1');
        }
    }
    cout << res;

#ifdef ZYC_LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

/**
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
      AnTi-MiRaGe on Anti-Mage xD
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <memory.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define show puts("Debug")

using namespace std;

const int N = 1e5 + 5;

string a, b, ans;

int pref[3][N], pr[3][N];

main()
{
    cin >> a >> b;
    a = ' ' + a;
    b = ' ' + b;
    for (int i = 1; i < sz(a); i++)
    {
        pref[1][i] = pref[1][i - 1] + (a[i] == 'B' || a[i] == 'C');
        if (a[i] != 'A')
            pr[1][i] = 0;
        else
            pr[1][i] = pr[1][i - 1] + 1;
    }
    for (int i = 1; i < sz(b); i++)
    {
        pref[2][i] = pref[2][i - 1] + (b[i] == 'B' || b[i] == 'C');
        if (b[i] != 'A')
            pr[2][i] = 0;
        else
            pr[2][i] = pr[2][i - 1] + 1;
    }
    int q, l, r, L, R;
    cin >> q;
    while (q--)
    {
        scanf("%d%d%d%d", &l, &r, &L, &R);

        if ( min(r - l + 1, pr[1][r]) >= min(R - L + 1, pr[2][R]) )
        {
            int need = 0;

            if (pr[2][R] == 0 && pr[1][r] > 0)
                need = 2;
            else
                need += ( (min(r - l + 1, pr[1][r]) -  min(R - L + 1, pr[2][R]) ) % 3) * 2;

            if (  (pref[2][R] - pref[2][L - 1]) >= (pref[1][r] - pref[1][l - 1] + need) &&  ( (pref[2][R] - pref[2][L - 1]) - (pref[1][r] - pref[1][l - 1] + need) ) % 2 == 0 )
                ans += '1';
            else
                ans += '0';
        }
        else
            ans += '0';
    }
    cout << ans << endl;
}
/**
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 C C B A C A C B C  C  C  B  B  A  A  C
 C A C C A A A B A  A  C  B  B  B  B  A C

CCBBAA
BBBAC
**/

#include<bits/stdc++.h>
using namespace std;

const int N=100010;
char a[N], b[N];
int n, m;
int s[N], t[N], prea[N], preb[N];

void yes() {
    putchar('1');
}
void no() {
    putchar('0');
}
int main() {
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    n = strlen(a + 1);
    m = strlen(b + 1);
    for (int i = 1; i <= n; ++i) {
        s[i] = s[i - 1] + (a[i] != 'A');
        if (a[i] != 'A') prea[i] = 0;
        else prea[i] = prea[i - 1] + 1;
    }
    for (int i = 1; i <= m; ++i) {
        t[i] = t[i - 1] + (b[i] != 'A');
        if (b[i] != 'A') preb[i] = 0;
        else preb[i] = preb[i - 1] + 1;
    }
    int Q;
    scanf("%d", &Q);
    while (Q--) {
        int l, r, h, g;
        scanf("%d%d%d%d", &l, &r, &h, &g);
        int len1 = r - l + 1, len2 = g - h + 1;
        int tot1 = s[r] - s[l - 1], tot2 = t[g] - t[h - 1];
        int a1 = len1 - tot1, a2 = len2 - tot2;
        int suf1 = min(a1, prea[r]), suf2 = min(a2, preb[g]);
        if (tot1 > tot2 || tot1 % 2 != tot2 % 2) {
            no();
            continue;
        }
        if (tot1 == tot2) {
            if (suf1 < suf2 || suf1 % 3 != suf2 % 3) no();
            else yes();
        } else {
            if (suf1 > suf2) yes();
            else if (suf1 < suf2) no();
            else {
                if (suf1 < a1) yes();
                else no();
            }
        }
    }
    puts("");
    return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define Ys { putchar('1'); continue; }
#define No { putchar('0'); continue; }

using namespace std;

const int N=100010;

char s[N],t[N];
int ps[N],pt[N],ls[N],lt[N],q,n,m;

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	scanf("%s",t+1); m=strlen(t+1);
	for(int i=1;i<=n;i++){
		ps[i]=ps[i-1]; ls[i]=ls[i-1];
		if(s[i]!='A') ps[i]++,ls[i]=i;
	}
	for(int i=1;i<=m;i++){
		pt[i]=pt[i-1]; lt[i]=lt[i-1];
		if(t[i]!='A') pt[i]++,lt[i]=i;
	}
	scanf("%d",&q);
	while(q--){
		int l,r,L,R;
		scanf("%d%d%d%d",&l,&r,&L,&R);
		if(ps[r]-ps[l-1]>pt[R]-pt[L-1]) No;
		if(ps[r]-ps[l-1]<pt[R]-pt[L-1]){
			if((pt[R]-pt[L-1])-(ps[r]-ps[l-1])&1) No;
			if(lt[R]==R && ls[r]==r) Ys;
			int t1=ls[r]>=l?r-ls[r]:r-l+1,t2=lt[R]>=L?R-lt[R]:R-L+1;
			if(t1<=t2) No;
			if(ls[r]!=r) Ys;
			if(lt[R]!=R) No;
			Ys;
		}
		int t1=ls[r]>=l?r-ls[r]:r-l+1,t2=lt[R]>=L?R-lt[R]:R-L+1;
		if(t2>t1) No;
		if((t1-t2)%3==0) Ys;
		No;
	}
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
//#define int lld
typedef int64_t lld;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
//#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
    return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
}
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T, N> &c ) {
     return _out(s,c.begin(),c.end());
}
inline char readchar() {
	const int S = 1<<20; // buffer size
	static char buf[S], *p = buf, *q = buf;
	if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
	return *p++;
}
inline void input(int &_x){
    _x = 0;
    int _tmp = 1; char _tc = readchar();
    while(_tc < '0' || _tc > '9') _tc = readchar();
    while(_tc >= '0' && _tc <= '9') _x = (_x<<1)+(_x<<3)+(_tc-48), _tc = readchar();
}
inline void output(int _x){
    char _buff[20]; int _f = 0;
    if(_x == 0) putchar('0');
    while(_x > 0){
            _buff[_f++] = _x%10+'0';
            _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
            putchar(_buff[_f]);
  putchar('\n');
}

vector<int> u, v, uu, vv;
signed main(){jizz; //freopen("test.in", "r", stdin);
#ifdef LOCAL
freopen("test.in", "r", stdin);
#endif
    string s, t;
    cin >> s >> t; u.pb(0), v.pb(0); uu.pb(0); vv.pb(0);
    for(auto c: s)u.pb(c != 'A');
    for(auto c: t)v.pb(c != 'A');
    for(auto c: s)uu.pb(c == 'A'?1+uu.back():0);
    for(auto c: t)vv.pb(c == 'A'?1+vv.back():0);
    for(int i = 1; i < u.size(); i++)u[i]+=u[i-1];
    for(int i = 1; i < v.size(); i++)v[i]+=v[i-1];
    int q;

    cin >> q;
    while(q--){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if(v[d]-v[c-1]){
            if((v[d]-v[c-1]) < (u[b]-u[a-1]))putchar('0');
            else if(((v[d]-v[c-1]) - (u[b]-u[a-1]))&1)putchar('0');
            else if(min(vv[b], b-a+1) < vv[d] || (min(vv[b], b-a+1)-vv[d])%3 != 0)putchar('0');
            else putchar('1');
        }else{
            if(u[b]-u[a-1])putchar('0');
            else if(b-a >= d-c && ((b-a)-(d-c)) %3 == 0)putchar('1');
            else putchar('0');
        }
    }
    //cout << u << v << endl;
}

#include <iostream>
#include <string>
#include <vector>

using namespace std;

string s,p;

vector <int> a,b,x,y;

int main(){

    cin >>s>>p;

    a.push_back(0); b.push_back(0); x.push_back(0); y.push_back(0);

    for(int i=0; i<s.size(); i++){

        a.push_back(a[a.size()-1]); x.push_back(x[x.size()-1]);
        if(s[i]!='A'){a[a.size()-1]++; x[x.size()-1]=i+1;}

    }

    for(int i=0; i<p.size(); i++){

        b.push_back(b[b.size()-1]); y.push_back(y[y.size()-1]);
        if(p[i]!='A'){b[b.size()-1]++; y[y.size()-1]=i+1;}

    }

    int q; int r1, r2;

    cin >>q; int i,j,k,l; int moze;

    for(; q>0; q--){

        moze=1;

        cin >>i>>j>>k>>l;

        if((b[l]-b[k-1])-(a[j]-a[i-1])<0)moze=0;
        if(((b[l]-b[k-1])-(a[j]-a[i-1]))%2)moze=0;

        r2=l-x[l]; r1=j-x[j];

        if(r1<j-i+1)r1=j-i+1; if(r2<l-k+1)r2=l-k+1;

        if(r1<r2)moze=0;

        else{

            if((r1-r2)%3!=0 && (b[l]-b[k-1])-(a[j]-a[i-1])==0)moze=0;

        }

        cout <<moze;

    }

return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+10;
const long long mod = 1e9 + 7;
const long double eps = 1e-7;

string s, t;
int q;

int cntBs[maxn];
int cntBt[maxn];
int sufAs[maxn];
int sufAt[maxn];

void preproc()
{
    for (int i = 1; i <= s.length(); ++i)
    {
        cntBs[i] = cntBs[i - 1] + (s[i - 1] == 'B' || s[i - 1] == 'C');
    }
    for (int i = 1; i <= t.length(); ++i)
    {
        cntBt[i] = cntBt[i - 1] + (t[i - 1] == 'B' || t[i - 1] == 'C');
    }
    for (int i = 1; i <= s.length(); ++i)
    {
        sufAs[i] = (s[i - 1] == 'A' ? (sufAs[i - 1] + 1) : 0);
    }
    for (int i = 1; i <= t.length(); ++i)
    {
        sufAt[i] = (t[i - 1] == 'A' ? (sufAt[i - 1] + 1) : 0);
    }
}

bool canGet(int l1, int r1, int l2, int r2)
{
    int b1 = cntBs[r1] - cntBs[l1 - 1];
    int b2 = cntBt[r2] - cntBt[l2 - 1];
    int a1 = min(r1 - l1 + 1, sufAs[r1]);
    int a2 = min(r2 - l2 + 1, sufAt[r2]);

    if (b2 && !b1)
        b1 += 2, a1--;

    if (a1 < a2)
        return false;

    while (a1 - 3 >= a2)
        a1 -= 3;

    if (a1 > a2)
        a1 = a2, b1 += 2;

    if (b2 < b1)
        return false;

    if ((b2 - b1) % 2)
        return false;
    b1 = b2;
    return true;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    cin >> s >> t >> q;
    preproc();
    string result = "";
    while (q--)
    {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        result.push_back(canGet(a,b,c,d)?'1':'0');
    }
    printf("%s\n", result.c_str());
}

//be name khoda

#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define sz(x) ((int)x.size())
#define all(v) v.begin(), v.end()
#define vi vector <int>
#define pb push_back
#define mp make_pair

typedef long long ll;

const int N = 2e5;

int pre[N][2];

void rep(string a, int ind)
{
	for(int i = 0; i < sz(a); i++)
	{
		pre[i + 1][ind] = pre[i][ind];
		if(a[i] != 'A')
			pre[i + 1][ind]++;
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string a, b;
	cin >> a >> b;
	rep(a, 0);
	rep(b, 1);
	int q;
	cin >> q;
	while(q--)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int ta = pre[b][0] - pre[a - 1][0];
		int tb = pre[d][1] - pre[c - 1][1];
		if(ta == tb && tb == 0 && b - a != d - c)
			cout << 0;
		else if(ta % 2 == tb % 2 && ta <= tb)
			cout << 1;
		else
			cout << 0;
	}
	cout << endl;
	return 0;
}

//��CF 947D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 111111;
int ls,lt,ss[N],bs[N],tt[N],bt[N];
char s[N],t[N];
int main()
{
	int q,i,j,l,r,x,y;
	scanf("%s%s",s+1,t+1);
	s[0]='_',t[0]='_';
	ls=strlen(s)-1,lt=strlen(t)-1;
	for(i=1;i<=ls;i=i+1){
		ss[i]=ss[i-1];
		bs[i]=bs[i-1];
		if(s[i]!='A')
			ss[i]=i,bs[i]++;
	}
	for(i=1;i<=lt;i=i+1){
		tt[i]=tt[i-1];
		bt[i]=bt[i-1];
		if(t[i]!='A')
			tt[i]=i,bt[i]++;
	}
	scanf("%d",&q);
	while(q--){
		scanf("%d%d%d%d",&l,&r,&x,&y);
		i=(r-ss[r])-(y-tt[y]);
		j=(bt[y]-bt[x-1])-(bs[r]-bs[l-1]);
		if(i<0){
			cout<<0;
			continue;
		}
		i%=3;
		j-=i*2;
		if(j<0)
			cout<<0;
		else
			cout<<1;
	}
	return 0;
}

#include <cassert>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <climits>
#include <cstddef>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <numeric>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <list>
#include <string>
#include <functional>
#include <utility>
using namespace std;
typedef long long llint;
vector<int> f(const std::string& s) {
    vector<int> ret(s.size() + 1, 0);
    for (auto i = 0; i < s.size(); ++i) {
        ret[i + 1] = ret[i] + (s[i] == 'A' ? 1 : 0);
    }
    return ret;
}
vector<int> g(const std::string& s) {
    vector<int> ret(s.size() + 1, 0);
    for (auto i = 0; i < s.size(); ++i) {
        if (s[i] == 'A') {
            ret[i + 1] = ret[i] + 1;
        }
    }
    return ret;
}
int main() {
    string s, t;
    int q;
    cin >> s >> t >> q;
    auto sa = f(s);
    auto ta = f(t);
    auto se = g(s);
    auto te = g(t);
    while (q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x = b - a + 1 - (sa[b] - sa[a - 1]);
        int y = d - c + 1 - (ta[d] - ta[c - 1]);
        if (x > y) {
            cout << 0;
        } else {
            int zs = min(b - a + 1, se[b]), zt = min(d - c + 1, te[d]);
            cout << (zs >= zt && zs % 3 == zt % 3 ? 1 - (y - x) % 2 : 0);
        }
    }
    cout << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 101000;
const int INF = 1000000007;
const double PI = acos(-1.0);

int cntP[MAXN], cntQ[MAXN];
int preP[MAXN], preQ[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    string P, Q;
    cin >> P >> Q;
    for (int i = 0; i < P.size(); ++i) {
        preP[i + 1] = preP[i];
        cntP[i + 1] = cntP[i];
        if (P[i] == 'A') continue;
        cntP[i + 1] = cntP[i] + 1;
        preP[i + 1] = i + 1;
    }
    for (int i = 0; i < Q.size(); ++i) {
        preQ[i + 1] = preQ[i];
        cntQ[i + 1] = cntQ[i];
        if (Q[i] == 'A') continue;
        cntQ[i + 1] = cntQ[i] + 1;
        preQ[i + 1] = i + 1;
    }

    int M;
    cin >> M;
    for (int i = 0; i < M; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int A = cntP[b] - cntP[a - 1];
        int B = cntQ[d] - cntQ[c - 1];
        if ((A + B) & 1) {
            cout << 0;
            continue;
        }
        if (A > B) {
            cout << 0;
            continue;
        }
        int B1 = preP[b], B2 = preQ[d];
        if (A == B) {
            if (A == 0) {
                if (b - a == d - c) cout << 1; else cout << 0;
                continue;
            }
            if (b - B1 == d - B2) cout << 1; else cout << 0;
            continue;
        }
        if (A == 0) {
            if (d - B2 < b - a + 1) cout << 1; else cout << 0;
            continue;
        }
        if (d - B2 < b - B1) cout << 1; else cout << 0;
    }
    cout << endl;

    return 0;
}

#include<bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vll;

ll const inf = ll(1e18);
int const mod = int(1e9) + 7;
int const N = int(1e5) + 5;

int preft[N];
int prefs[N];
int trailt[N];
int trails[N];

int main(){
    ios_base::sync_with_stdio(false);
    ifstream in("input.txt");
    //cin.rdbuf(in.rdbuf());
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for(int i = 0; i < (int)s.size(); ++i){
        if(s[i] != 'A'){
            ++prefs[i + 1];
            cnt = 0;
        }else{
            ++cnt;
        }
        prefs[i + 1] += prefs[i];
        trails[i + 1] = cnt;
    }
    cnt = 0;
    for(int i = 0; i < (int)t.size(); ++i){
        if(t[i] != 'A'){
            ++preft[i + 1];
            cnt = 0;
        }else{
            ++cnt;
        }
        preft[i + 1] += preft[i];
        trailt[i + 1] = cnt;
    }
    int q;
    cin >> q;
    while(q--){
       int l1, r1, l2, r2;
       cin >> l1 >> r1 >> l2 >> r2;
       int cnt1 = prefs[r1] - prefs[l1 - 1];
       int cnt2 = preft[r2] - preft[l2 - 1];
       int tr1 = min(trails[r1], r1 - l1 + 1);
       int tr2 = min(trailt[r2], r2 - l2 + 1);
       int flag1 = tr1 >= tr2;
       int del = min(2, (cnt2 - cnt1) / 2);
       bool flag3 = false;
       for(int j = tr1; j >= max(tr1 - del, tr2); --j){
            flag3 |= (j - tr2) % 3 == 0;
       }
       int flag2 = cnt2 >= cnt1 && (cnt2 - cnt1) % 2 == 0;
       //cout << cnt1 << " " << cnt2 << " " << flag1 << " " << flag2 << endl;
       cout << (flag1 && flag2 && flag3);
       //--l1; --r1; --l2; --r2;
    }
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>

std::tuple<std::vector<int>, std::vector<int>> GetCountsAndLastIndices(const std::string& input_string) {
    std::vector<int> counts(input_string.size() + 1, 0);
    std::vector<int> last_indices(input_string.size() + 1, -1);
    for (int i = 0; i < static_cast<int>(input_string.size()); ++i) {
        counts[i + 1] = counts[i] + (input_string[i] != 'A');
        last_indices[i + 1] = last_indices[i];
        if (input_string[i] != 'A') {
            last_indices[i + 1] = i;
        }
    }
    return std::make_tuple(counts, last_indices);
}

int main() {
    std::string s;
    std::string t;
    std::cin >> s;
    std::cin >> t;
    std::vector<int> s_counts;
    std::vector<int> t_counts;
    std::vector<int> t_last_indices;
    std::vector<int> s_last_indices;
    std::tie(s_counts, s_last_indices) = GetCountsAndLastIndices(s);
    std::tie(t_counts, t_last_indices) = GetCountsAndLastIndices(t);
    int q;
    std::cin >> q;
    for (int i = 0; i < q; ++i) {
        int a,b,c,d;
        std::cin >> a >> b >> c >> d;
        --a;
        --c;
        int s_count = s_counts[b] - s_counts[a];
        int t_count = t_counts[d] - t_counts[c];
        int last_s_count = b - std::max(a, s_last_indices[b]);
        int last_t_count = d - std::max(c, t_last_indices[d]);
        if ((s_count + t_count) % 2 == 0 && ((s_count == t_count && last_s_count == last_t_count) || (s_count < t_count && last_s_count >= last_t_count))) {
            std::cout << "1";
        } else {
            std::cout << "0";
        }
    }
    std::cout << std::endl;
    return 0;
}

#include <bits/stdc++.h>
#define N 200100
using namespace std;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
char sd[N],ss[N];
int A[N],B[N],q,len1,len2,ls[N],ld[N];
int main()
{
	// freopen("read.in","r",stdin);
	scanf("%s",sd); len1=strlen(sd);
	for(int i=0;i<len1;i++)
		A[i+1]=(sd[i]=='B'||sd[i]=='C');
	scanf("%s",ss); len2=strlen(ss);
	for(int i=0;i<len2;i++)
		B[i+1]=(ss[i]=='B'||ss[i]=='C');
	for(int i=1;i<=len1;i++)
		A[i]+=A[i-1];
	for(int i=1;i<=len2;i++)
		B[i]+=B[i-1];
	for(int i=0,j=0;i<len1;i++)
	{
		if(sd[i]!='A') j=i+1;
		ls[i+1]=i-j+1;
	}
	for(int i=0,j=0;i<len2;i++)
	{
		if(ss[i]!='A') j=i+1;
		ld[i+1]=i-j+1;
	}
	q=read();
	while(q--)
	{
		int l=read(), r=read(), a=read(), b=read();
		int X=A[r]-A[l-1];
		int Y=B[b]-B[a-1];
		if((X&1)==(Y&1)&&X<=Y)
		{
			int aa=min(ls[r],r-l+1),
				bb=min(ld[b],b-a+1);
				// a=13; b=10;
			if(!bb&&aa&&X+1<=Y) {putchar('1');continue;}
			if(aa<bb||((aa%3)-bb)*2+X>Y)
				putchar('0');
			else putchar('1');
		}
		else putchar('0');
	}
	puts("");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

string s, t;
int sc[100005];
int bc[100005];
int ca[100005], cb[100005];;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		sc[i + 1] = sc[i] + (s[i] != 'A');
		ca[i + 1] = ca[i] + (s[i] == 'A');
	}
	for (int i = 0; i < t.size(); i++) {
		bc[i + 1] = bc[i] + (t[i] != 'A');
		cb[i + 1] = cb[i] + (t[i] == 'A');
	}
	int q;
	cin >> q;
	while (q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int k = (bc[d] - bc[c - 1]) - (sc[b] - sc[a - 1]);
		if (k >= 0) {
			int k1 = 0, k2 = 0;
			int le, ri, mid;
			le = a;
			ri = b;
			while (le <= ri) {
				mid = (le + ri) / 2;
				if (ca[b] - ca[mid - 1] == b - mid + 1) {
					k1 = b - mid + 1;
					ri = mid - 1;
				}
				else le = mid + 1;
			}
			le = c;
			ri = d;
			while (le <= ri) {
				mid = (le + ri) / 2;
				if (cb[d] - cb[mid - 1] == d - mid + 1) {
					k2 = d - mid + 1;
					ri = mid - 1;
				}
				else le = mid + 1;
			}
			if (k1 < k2)cout << '0';
			else if (k == 0) {
				cout << (k1 % 3 == k2 % 3);
			}
			else {
				cout << (k % 2 == 0);
			}
		}
		else {
			cout << '0';
		}
	}
	cout << '\n';
	return 0;
}
/*
CCBACACBCCCBBAAC
CACCAAABAACBBBBAC
1
13 15 8 12
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
#define REP(i,n) for (int i=1;i<=n;++i)
#define FOR(i,n) for (__typeof(n.begin())i=n.begin();i!=n.end();++i)
using namespace std;

char s1[100010];
char s2[100010];
int n1,n2,m,l1,r1,l2,r2;
int a[100010];
int b[100010];
int c[100010];
int d[100010];

// BBBBBB1 AAAAA1
// BBB2 AAAAAAAAA2
bool check(int b1, int b2, int a1, int a2) {
	if (b1>b2) return false;
	if (b1==b2) return (a1>=a2 and (a1-a2)%3==0);
	if ((b2-b1)%2) return false;
	if (b1==0 && a1>=a2) return true;
	if (b1>0 && a1>a2) return true;
	return false;
}

int main() {
	scanf("%s",s1);
	scanf("%s",s2);
	n1=strlen(s1);
	n2=strlen(s2);
	// A=0 B=1
	REP(i,n1) a[i]=(s1[i-1]!='A');
	REP(i,n2) b[i]=(s2[i-1]!='A');
	REP(i,n1) if (a[i]==0) c[i]=c[i-1]+1;
	REP(i,n2) if (b[i]==0) d[i]=d[i-1]+1;
	REP(i,n1) a[i]+=a[i-1];
	REP(i,n2) b[i]+=b[i-1];
	scanf("%d",&m);
	REP(i,m) {
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		bool ans=check(a[r1]-a[l1-1],b[r2]-b[l2-1],c[r1],d[r2]);
		printf(ans?"1":"0");
	}
	puts("");
	return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#define oo 2139062143
#define fo(i,x,y) for (int i=(x);i<=(y);++i)
using namespace std;
const int N=1001000;
int s[N],t[N],n,m,la[N],lb[N];
char c[N],d[N];
int main()
{
	// freopen("D:/LiuYuanHao/a.in","r",stdin);
	scanf("%s\n",c+1);
	n=strlen(c+1);fo(i,1,n)
	{
		la[i]=la[i-1];
		s[i]=((c[i]!='A')?1:0)+s[i-1];
		if(c[i]!='A') la[i]=i;
	}
	scanf("%s\n",d+1);
	m=strlen(d+1);fo(i,1,m)
	{
		lb[i]=lb[i-1];
		t[i]=((d[i]!='A')?1:0)+t[i-1];
		if(d[i]!='A') lb[i]=i;
	}
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int x,y,u,v;
		scanf("%d%d%d%d",&x,&y,&u,&v);
		int cnt1=s[y]-s[x-1],cnt2=t[v]-t[u-1];
		if(cnt1>cnt2||((cnt1&1)!=(cnt2&1)))
		{
			printf("0");
			continue;
		}
		int tp=(y-max(la[y],x-1))-(v-max(lb[v],u-1));
		if(tp>=0)
		{
			if(cnt1==0&&cnt2!=0&&tp==0)
			{
				printf("0");
				continue;
			}
			if(tp%3==0)
			{
				printf("1");
				continue;
			}
		}
		printf("0");
	}
	printf("\n");
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define cin_desync()                      \
	do {                                  \
		ios_base::sync_with_stdio(false); \
		cin.tie(0);                       \
	} while (0)                           \

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int max_N = 1e5 + 10;
int prefS[max_N], prefT[max_N];
char S[max_N], T[max_N];

int query(int *pref, int i, int j);

int main()
{
    cin_desync();
    cin >> (S + 1) >> (T + 1);

    int M = strlen(S + 1), N = strlen(T + 1);
    for (int i = 1; i <= M; ++i) {
        prefS[i] = prefS[i - 1] + (S[i] != 'A');
    }
    for (int i = 1; i <= N; ++i) {
        prefT[i] = prefT[i - 1] + (T[i] != 'A');
    }

    int Q;
    cin >> Q;
    while(Q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;

        cout << ((query(prefS, a, b) % 2) == (query(prefT, c, d) % 2));
    }
}

int query(int *pref, int i, int j)
{
    return pref[j] - pref[i - 1];
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define fo(i,a,b) for (i=a; i<=b; i++)
using namespace std;

const int N=100005;
int q, n, m, i, x, y, xx, yy, s0, s1, t0, t1;
char ch, s[N], t[N];
int a[N], b[N], c[N], d[N];

int main()
{
	//freopen("d.in","r",stdin); freopen("d.out","w",stdout);

	while (1)
	{
		scanf("%c",&ch);
		if (ch=='\n') break; else
		if (ch=='A') s[++n]='1'; else s[++n]='0';
	}
	//fo(i,1,n) printf("%c",s[i]); printf("\n");
	fo(i,1,n)
	{
		a[i]=a[i-1]+(s[i]=='0');
		if (s[i]=='0') b[i]=0; else b[i]=b[i-1]+1;
	}

	while (1)
	{
		scanf("%c",&ch);
		if (ch=='\n') break; else
		if (ch=='A') t[++m]='1'; else t[++m]='0';
	}
	//fo(i,1,m) printf("%c",t[i]); printf("\n");
	fo(i,1,m)
	{
		c[i]=c[i-1]+(t[i]=='0');
		if (t[i]=='0') d[i]=0; else d[i]=d[i-1]+1;
	}

	scanf("%d",&q);
	while (q)
	{
		q--, scanf("%d%d%d%d",&x,&y,&xx,&yy);
		s0=a[y]-a[x-1], t0=c[yy]-c[xx-1];
		s1=min(b[y],y-x+1), t1=min(d[yy],yy-xx+1);
		if (s0>t0) printf("0"); else
		if (s0%2!=t0%2) printf("0"); else
		if (s1<t1) printf("0"); else
		if (!s0 && t0 && s1==t1) printf("0"); else
		if (s1%3==t1%3) printf("1"); else
		if (s0==t0) printf("1"); else printf("0");
	}
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20);
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < int(s.size()); ++i) if (s[i] == 'C') s[i] = 'B';
  for (int i = 0; i < int(t.size()); ++i) if (t[i] == 'C') t[i] = 'B';

  vector<int> as(s.size(), 1), at(t.size(), 1), bs(s.size()+1, 0), bt(t.size()+1, 0);

  for (int i = 0; i < int(s.size()); ++i){
    if (i != 0) as[i] = as[i-1]+1;
    if (s[i] != 'A') as[i] = 0;
  }
  for (int i = 0; i < int(t.size()); ++i){
    if (i != 0) at[i] = at[i-1]+1;
    if (t[i] != 'A') at[i] = 0;
  }

  for (int i = 0; i < int(s.size()); ++i) bs[i+1] = bs[i]+(s[i] == 'B');
  for (int i = 0; i < int(t.size()); ++i) bt[i+1] = bt[i]+(t[i] == 'B');

  int q;
  cin >> q;
  for (int i =0; i < q; ++i){
    int a, b, c, d;
    cin >> a >> b >> c >> d;--a;--b;--c;--d;
    int qbo = bs[b+1]-bs[a], qbf = bt[d+1]-bt[c];
    int lao = min(as[b], b-a+1) , laf = min(at[d], d-c+1);

    //cerr << "hey" << endl;
    //cerr << a << " " << b << " " << c << " "  << d << endl;
   // cerr << qbo << " " << qbf <<  " "  << lao << " " << laf << endl;
    if (qbo % 2 != qbf % 2 or qbo > qbf or laf > lao){
      cout << 0;
      continue;
    }
    if (laf%3 == lao%3){
      cout << 1;
      continue;
    }
    if (qbo + 2 <= qbf){
      cout << 1;
    }
    else cout << 0;
  }
  cout << endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <random>
#include <climits>
#include <iomanip>
#include <queue>
#include <bitset>
#include <cctype>
#include <ostream>
#include <functional>
using namespace std;

#define forn(i,n) for (int i = 0;i < int(n);i++)
#define ford(i,n) for (int i = n-1;i >=0;i--)
#define fore(i,l,r) for (int i = int(l);i < int(r);i++)
#define correct(x,n) (((x) >= 0) && ((x) < n))
#define mp(a,b) make_pair((a),(b))
#define all(a) (a).begin(),(a).end()
#define rnd() (rand() + (RAND_MAX+1)*rand())
//#define DEBUG_

#define x first
#define y second

typedef long long li;
typedef vector<int> vi;
typedef vector<li> vli;
typedef pair<int, int> pi;
typedef pair<li, li> pli;
typedef vector<pi> vpi;
typedef vector<pli> vpli;
typedef vector<vector<int>> vvi;
typedef vector<vector<li>> vvli;
typedef long double ld;
typedef pair<li, li> Point;

class StringInfGetter
{
public:
	string &s;
	vi a, b;
	int n;

	StringInfGetter(string &s1) :s(s1)
	{
		n = s.size();
		a.assign(n+1, 0);
		b.assign(n+1, 0);
		int anum = 0;
		forn(i, n)
		{
			anum = (s[i] == 'A' ? anum + 1 : 0);
			b[i + 1] = b[i] + (s[i] == 'B' || s[i] == 'C');
			a[i + 1] = anum;
		}
	}

	pi getInf(int l, int r)
	{
		return mp(min(r - l + 1, a[r]), b[r] - b[l - 1]);
	}
};

bool canConst(pi a, pi b)
{
	if (a == b)
		return 1;
	if (b.y - a.y < 0 || (b.y - a.y) % 2)
		return 0;
	if (b.y != a.y && a.x >= b.x)
		return 1;
	if (b.y == a.y && a.x >= b.x && (a.x - b.x) % 3 == 0)
		return 1;
	return 0;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	string s, t;
	cin >> s >> t;
	StringInfGetter a(s), b(t);
	int n;
	cin >> n;
	forn(i, n)
	{
		int l1, r1, l2, r2;
		cin >> l1 >> r1 >> l2 >> r2;
		pi p = a.getInf(l1, r1);
		pi q = b.getInf(l2, r2);
		cout << canConst(p, q);
	}
}

#ifndef LOCAL
#define NDEBUG 1
#endif
#include<bits/stdc++.h>

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	std::string s,t;std::cin>>s>>t;
	for(char& c:s) if(c=='B') c='C';
	for(char& c:t) if(c=='B') c='C';
	int nquery;std::cin>>nquery;

	auto const ntaila=[](std::string const& s){
		std::vector<int> ntaila(s.size()+1);
		for(unsigned i=1;i<s.size();++i)
			ntaila[i]=s[i-1]=='A' ? ntaila[i-1]+1 : 0;
		return ntaila;
	};
	auto const nsuffixb=[](std::string const& s){
		std::vector<int> nsuffixb(s.size()+1);
		for(auto i=s.size();i--;)
			nsuffixb[i]=nsuffixb[i+1]+(s[i]=='B');
		return nsuffixb;
	};

	auto const s_ntaila=ntaila(s);
	auto const t_ntaila=ntaila(t);
	auto const s_nsuffixb=nsuffixb(s);
	auto const t_nsuffixb=nsuffixb(t);

	while(nquery--){
		int sl,sr,tl,tr;std::cin>>sl>>sr>>tl>>tr;
		--sl;--tl;

		int s_nta=s_ntaila[sr];
		int s_nb=s_nsuffixb[sl]-s_nsuffixb[sr];
		int t_nta=t_ntaila[tr];
		int t_nb=t_nsuffixb[tl]-t_nsuffixb[tr];

		if(s_nta>=t_nta and s_nb<=t_nb and (s_nb&1)==(t_nb&1)){
			s_nta-=(s_nta-t_nta)/3*3;
			assert(t_nb-s_nb>=0);
			assert(s_nta-t_nta>=0);
			assert(s_nta-t_nta<3);
			if(t_nb-s_nb < s_nta-t_nta)
				std::cout<<'0';
			else
				std::cout<<'1';
		}else{
			std::cout<<'0';
		}
	}
	std::cout<<'\n';
}
// There are so many special cases. I hope this is correct.
// UPD: Just a typo...

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define ll long long
#define ull  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 1100000;
int sa[N], sb[N], fa[N], fb[N], a[N], b[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s, t;
    cin >> s;
    cin >> t;
    int n = s.length();
    int m = t.length();
    for (int i = 0; i < n; i++){
        if (s[i] == 'B' || s[i] == 'C'){
            a[i + 1] = 1;
        } else{
            a[i + 1] = 0;
        }
    }
    for (int i = 0; i < m; i++){
        if (t[i] == 'B' || t[i] == 'C'){
            b[i + 1] = 1;
        } else{
            b[i + 1] = 0;
        }
    }
    for (int i = 1; i <= n; i++){
        sa[i] = a[i] + sa[i - 1];
        if (a[i] == 0) fa[i] = fa[i - 1] + 1; else fa[i] = 0;
    }
    for (int i = 1; i <= m; i++){
        sb[i] = b[i] + sb[i - 1];
        if (b[i] == 0) fb[i] = fb[i - 1] + 1; else fb[i] = 0;
    }
    int q;
    cin >> q;
    while(q--){
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        int x = sa[r1] - sa[l1 - 1];
        int y = sb[r2] - sb[l2 - 1];
        if (y < x || x % 2 != y % 2){
            cout << 0;
            continue;
        }
        int L1 = fa[r1];
        if (L1 > r1 - l1 + 1) L1 = r1 - l1 + 1;
        int L2 = fb[r2];
        if (L2 > r2 - l2 + 1) L2 = r2 - l2 + 1;
        if (L1 < L2){
            cout << 0;
            continue;
        }
        if (y > x){
            cout << 1;
            continue;
        }
        if (L1 < L2 || L1 % 3 != L2 % 3){
            cout << 0;
        } else
            cout << 1;
    }
}

#include<bits/stdc++.h>
#include<fstream>
#define FIN freopen("in.txt","r",stdin);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
typedef long long LL;

const int MX = 1e5 + 5;

char s[MX], t[MX];
int sum1[MX], sum2[MX];
int pre1[MX], pre2[MX];

int main() {
    //FIN;
    scanf ("%s%s", s + 1, t + 1);
    int n = strlen (s + 1), m = strlen (t + 1);
    for (int i = 1; i <= n; i++) {
        sum1[i] = sum1[i - 1] + (s[i] != 'A');
        pre1[i] = s[i] == 'A' ? pre1[i - 1] + 1 : 0;
    }
    for (int i = 1; i <= m; i++) {
        sum2[i] = sum2[i - 1] + (t[i] != 'A');
        pre2[i] = t[i] == 'A' ? pre2[i - 1] + 1 : 0;
    }
    int q; scanf ("%d", &q);
    while (q--) {
        int a, b, c, d;
        scanf ("%d%d%d%d", &a, &b, &c, &d);
        int x = sum1[b] - sum1[a - 1] - sum2[d] + sum2[c - 1];
        int y = min (b - a + 1, pre1[b]) - min (d - c + 1, pre2[d]);
        if (x < 0 || x % 2 == 1 || y < 0 || y == 0 && x > 0 && sum1[b] - sum1[a - 1] == 0) printf ("0");
        else if (y == 0 || x >= 0 || y % 3 == 0) printf ("1");
        else printf ("0");
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

const int maxn = 1e5 + 5;
char s[maxn];
char t[maxn];
int q;
int n, m;
int f[maxn];
int g[maxn];
int dd[maxn];
int ee[maxn];

void chemthan() {
    cin >> s >> t;
    n = strlen(s), m = strlen(t);
    FOR(i, 0, n) {
        f[i + 1] = s[i] != 'A';
        if (s[i] == 'A') {
            dd[i + 1] = dd[i] + 1;
        }
    }
    FOR(i, 0, m) {
        g[i + 1] = t[i] != 'A';
        if (t[i] == 'A') {
            ee[i + 1] = ee[i] + 1;
        }
    }
    partial_sum(f, f + n + 1, f);
    partial_sum(g, g + m + 1, g);
    cin >> q;
    while (q--) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        if (ee[d] >= d - c + 1 && dd[b] >= b - a + 1 && (b - a + 1) >= (d - c + 1) && (b - a - d + c) % 3 == 0) {
            cout << 1;
            continue;
        }
        if (min(b - a + 1, dd[b]) < min(d - c + 1, ee[d])) {
            cout << 0;
            continue;
        }
        b -= min(d - c + 1, ee[d]), d -= min(d - c + 1, ee[d]);
        int sbc = f[b] - f[a - 1];
        int tbc = g[d] - g[c - 1];
        if (sbc > tbc) {
            cout << 0;
            continue;
        }
        if (sbc + tbc & 1) {
            cout << 0;
            continue;
        }
        if (c <= d) {
            int x = min(b - a + 1, dd[b]);
            if (x % 3) {
                cout << 0;
                continue;
            }
            b -= x;
        }
        if (a > b && c <= d) {
            cout << 0;
            continue;
        }
        if (sbc <= tbc) {
            cout << 1;
        }
        else {
            cout << 0;
        }
    }
    cout << "\n";
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

string s, t;
int n, m;
int sa_cont[110000];
int sb_count[110000];
int ta_cont[110000];
int tb_count[110000];

int q;

void prepare(){
    n = s.size();
    m = t.size();
    for(int i = 1;i <= n;i++){
        if(s[i-1] == 'A'){
            sa_cont[i] = sa_cont[i-1] + 1;
            sb_count[i] = sb_count[i-1];
        }
        else{
            sa_cont[i] = 0;
            sb_count[i] = sb_count[i-1] + 1;
        }

    }
    for(int i = 1;i <= m;i++){
        if(t[i-1] == 'A'){
            ta_cont[i] = ta_cont[i-1] + 1;
            tb_count[i] = tb_count[i-1];
        }
        else{
            ta_cont[i] = 0;
            tb_count[i] = tb_count[i-1] + 1;
        }

    }
}

int solve(){
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int last_a = min(ta_cont[d],  d-c+1);
    if(sa_cont[b] < last_a)return false;
    b -= last_a;
    d -= last_a;
    int s_cnt = sb_count[b] - sb_count[a-1];
    int t_cnt = tb_count[d] - tb_count[c-1];
    if(d < c){
        return s_cnt <= 0 && ((b-a)-(d-c))%3==0;
    }
    if(b < a)return false;
    if(s[b] == 'A'){
        int a_cnt = min(b-a+1, sa_cont[b]);
        if(a_cnt % 3)s_cnt += 2;
    }
    if(s_cnt % 2 != t_cnt % 2)return false;
    return s_cnt <= t_cnt;
}

int main(){
    cin >> s >> t;
    cin >> q;
    prepare();
    while(q--)printf("%d", solve());
    puts("");
    return 0;
}

#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef double db;
using namespace std;
char check(int& a, int& b, int& c, int& d, vector<int>& cnt_s, vector<int>& cnt_t, vector<int>& con_s, vector<int>& con_t)
{
	int Con_s = min(con_s[b], b - a + 1), Con_t = min(con_t[d], d - c + 1);
	if (Con_s < Con_t)
		return '0';
	int Cnt_s = cnt_s[b] - cnt_s[a - 1], Cnt_t = cnt_t[d] - cnt_t[c - 1];
	if (Con_s > Con_t)
		Cnt_s += 2;
	if (Cnt_s <= Cnt_t && (Cnt_t - Cnt_s) % 2 == 0)
		return '1';
	else
		return '0';
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	string s, t;
	cin >> s >> t;
	s = '*' + s;
	t = '*' + t;
	vector<int> cnt_s(s.size()), cnt_t(t.size());
	cnt_s[0] = cnt_t[0] = 0;
	for (int i = 1; i < s.size(); ++i)
		cnt_s[i] = cnt_s[i - 1] + (s[i] != 'A');
	for (int i = 1; i < t.size(); ++i)
		cnt_t[i] = cnt_t[i - 1] + (t[i] != 'A');
	vector<int> con_s(s.size()), con_t(t.size());
	con_s[1] = (s[1] == 'A');
	con_t[1] = (t[1] == 'A');
	for (int i = 2; i < s.size(); ++i)
		con_s[i] = (s[i] == 'A') ? (con_s[i - 1] + 1) : 0;
	for (int i = 2; i < t.size(); ++i)
		con_t[i] = (t[i] == 'A') ? (con_t[i - 1] + 1) : 0;
	int q;
	cin >> q;
	string ans(q, '1');
	while (q--)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		ans[q] = check(a, b, c, d, cnt_s, cnt_t, con_s, con_t);
	}
	reverse(all(ans));
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;

void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b) % mo;
}

const int maxn = 1e5+5;

int p[maxn], q[maxn];
int ta[maxn], sa[maxn];

signed main(){
    IOS();
    string s,t; cin>>s>>t;
    int n = s.length(), m = t.length();
    for (int i = 0; i<n; ++i) {
        p[i+1] = s[i] != 'A';
        p[i+1] += p[i];
        if (s[i] == 'A') {
            sa[i+1] = sa[i] + 1;
        }else{
            sa[i+1] = 0;
        }
    }
    for (int i = 0; i<m; ++i) {
        q[i+1] = t[i] != 'A';
        q[i+1] += q[i];
        if (t[i] == 'A') {
            ta[i+1] = ta[i] + 1;
        }else{
            ta[i+1] = 0;
        }
    }
    int Q; cin>>Q;
    while (Q--) {
        int l,r,L,R;
        cin>>l>>r>>L>>R;
        int a = p[r]-p[l-1], b = q[R]-q[L-1];
        if (a%2 != b%2 || a>b) cout<<0;
        else {
            int SA = min(sa[r], r-l+1);
            int TA = min(ta[r], R-L+1);
            if ((a==b && (SA%3 != TA % 3)) || (SA < TA) ) cout<<0;
            else{
                cout<<1;
            }
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
char S[100000 + 5], T[100000 + 5];
int Sa[100000 + 5], Sb[100000 + 5], Ta[100000 + 5], Tb[100000 + 5], tailS[100000 + 5], tailT[100000 + 5];
int Q, a, b, c, d;//B可以凭空成双产生
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	scanf("%s%s", S + 1, T + 1);
	int lenS = strlen(S + 1);
	int lenT = strlen(T + 1);
	scanf("%d", &Q);
	for (int i = 1; i <= lenS; i++) {
		Sa[i] = Sa[i - 1] + (S[i] == 'A');
		Sb[i] = Sb[i - 1] + (S[i] != 'A');
		if (S[i] == 'A')tailS[i] = tailS[i - 1] + 1;
		else tailS[i] = 0;
	}
	for (int i = 1; i <= lenT; i++) {
		Ta[i] = Ta[i - 1] + (T[i] == 'A');
		Tb[i] = Tb[i - 1] + (T[i] != 'A');
		if (T[i] == 'A')tailT[i] = tailT[i - 1] + 1;
		else tailT[i] = 0;
	}
	for (int i = 0; i < Q; i++) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int ans = 1;
		int diffb = Tb[d] - Tb[c - 1] - Sb[b] + Sb[a - 1];
		int tS = min(b - a + 1, tailS[b]);
		int tT = min(d - c + 1, tailT[d]);
		if (diffb < 0 || tT - tS>0 || diffb % 2 == 1)ans = 0;
		int remain = (tS - tT) % 3 > 0;
		if (diffb - remain * 2 < 0)ans = 0;
		//if (Sb[b] - Sb[a - 1] == 0 && diffb)ans = 0;
		printf("%d", ans);
	}
}

#include <fstream>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

const int MAXN = 100000;

char s[1 + MAXN], t[1 + MAXN];
int suma[1 + MAXN], sumb[1 + MAXN], suffixa[1 + MAXN], suffixb[1 + MAXN];

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    scanf("%s%s", s + 1, t + 1);
    int n = strlen(s + 1), m = strlen(t + 1), as = 0;
    for (int i = 1; i <= n; i++) {
        suma[i] = suma[i - 1] + (s[i] != 'A');
        if (s[i] == 'A')
            as++;
        else
            as = 0;
        suffixa[i] = as;
    }
    int bs = 0;
    for (int i = 1; i <= m; i++) {
        sumb[i] = sumb[i - 1] + (t[i] != 'A');
        if (t[i] == 'A')
            bs++;
        else
            bs = 0;
        suffixb[i] = bs;
    }
    int q;
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        int l1 = y1 - x1 + 1, l2 = y2 - x2 + 1;
        bool ok = true;
        int a1 = min(suffixa[y1], l1), a2 = min(suffixb[y2], l2), b1 = suma[y1] - suma[x1 - 1], b2 = sumb[y2] - sumb[x2 - 1];
        if (abs(b2 - b1) % 2) {
            printf("0");
            continue;
        }
        if (!b1 && !b2) {
            if (a2 >= a1 && (a2 - a1) % 3 == 0)
                printf("1");
            else
                printf("0");
            continue;
        }
        if (!b1) {
            if (a1 >= a2 + 1)
                printf("1");
            else
                printf("0");
            continue;
        }
        if (a1 < a2)
            ok = false;
        if ((a1 - a2) % 3 != 0) {
            a1--;
            if (b1 + 2 > b2 || (b1 - b2) % 2 != 0)
                ok = false;
        }
        else
            if (b1 > b2 || (b1 - b2) % 2 != 0)
                ok = false;
        if (ok)
            printf("1");
        else
            printf("0");
    }
    return 0;
}

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

int A[2][100005],B[2][100005],T[2][100005];
char s[2][100005];
int main(){
	fup(i,0,1,1)scanf("%s",s[i]+1);
	int n=strlen(s[0]+1),m=strlen(s[1]+1);
	fup(i,1,n,1){
		A[0][i]=A[0][i-1], B[0][i]=B[0][i-1];
		if(s[0][i]=='A')A[0][i]++,T[0][i]=T[0][i-1]+1;
		else B[0][i]++;
	}
	fup(i,1,m,1){
		A[1][i]=A[1][i-1], B[1][i]=B[1][i-1];
		if(s[1][i]=='A')A[1][i]++,T[1][i]=T[1][i-1]+1;
		else B[1][i]++;
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int l,r,x,y;
		scanf("%d%d%d%d",&l,&r,&x,&y);
		int a1=A[0][r]-A[0][l-1],b1=B[0][r]-B[0][l-1],t1=min(T[0][r],r-l+1);
		int a2=A[1][y]-A[1][x-1],b2=B[1][y]-B[1][x-1],t2=min(T[1][y],y-x+1);
		if((b1+b2)%2 || b1>b2){
			putchar('0');
			continue;
		}
		if(!b1 && !b2){
			putchar(t1>=t2 && t1%3==t2%3?'1':'0');
		}else{
			putchar(t1>t2?'1':'0');
		}
	}
}