#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
#pragma GCC Optimize("Ofast")
long long sms[maxn], smt[maxn];
long long lsts[maxn], lstt[maxn];
int main() {
  string s, t;
  cin >> s >> t;
  for (long long i = 1; i <= (s).size(); i++) {
    lsts[i] = lsts[i - 1];
    if (s[i - 1] == 'B' || s[i - 1] == 'C') lsts[i] = i;
    sms[i] = sms[i - 1] + (s[i - 1] == 'B' || s[i - 1] == 'C');
  }
  for (long long i = 1; i <= (t).size(); i++) {
    lstt[i] = lstt[i - 1];
    if (t[i - 1] == 'B' || t[i - 1] == 'C') lstt[i] = i;
    smt[i] = smt[i - 1] + (t[i - 1] == 'B' || t[i - 1] == 'C');
  }
  long long q;
  cin >> q;
  string ans;
  while (q--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long ones = sms[b] - sms[a - 1], onet = smt[d] - smt[c - 1];
    long long zeros = b - max(lsts[b], a - 1), zerot = d - max(lstt[d], c - 1);
    if (ones > onet || (ones % 2) != (onet % 2) || zeros < zerot) {
      ans += "0";
      continue;
    }
    if (ones == onet && (zeros % 3) != (zerot % 3)) {
      ans += "0";
      continue;
    }
    if (zeros == zerot && zeros == b - a + 1 && onet > 0) {
      ans += "0";
      continue;
    }
    ans += "1";
  }
  cout << ans;
}
