#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int S[maxn], T[maxn], n, m, Q;
int sumS[maxn], sumT[maxn];
int saS[maxn], saT[maxn];
int main() {
  ios::sync_with_stdio(0);
  string tmp;
  cin >> tmp;
  n = tmp.size();
  for (int i(1); i <= n; ++i) {
    S[i] = tmp[i - 1] == 'A' ? 0 : 1;
    sumS[i] = sumS[i - 1] + S[i];
    if (!S[i]) saS[i] = saS[i - 1] + 1;
  }
  cin >> tmp;
  m = tmp.size();
  for (int i(1); i <= m; ++i) {
    T[i] = tmp[i - 1] == 'A' ? 0 : 1;
    sumT[i] = sumT[i - 1] + T[i];
    if (!T[i]) saT[i] = saT[i - 1] + 1;
  }
  cin >> Q;
  while (Q--) {
    int l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    int a = sumS[r1] - sumS[l1 - 1];
    int b = sumT[r2] - sumT[l2 - 1];
    int Sa = min(r1 - l1 + 1, saS[r1]);
    int Ta = min(r2 - l2 + 1, saT[r2]);
    if (b - a < 0 || Sa < Ta || (b - a) % 2 == 1)
      putchar('0');
    else {
      int x = ((Sa - Ta) % 3 != 0);
      if (b - a - 2 * x < 0)
        putchar('0');
      else if (a == 0 && b != a && Sa == Ta)
        putchar('0');
      else
        putchar('1');
    }
  }
  puts("");
  return 0;
}
