#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct SS {
  char s[N];
  int sum[N], l, a[N];
  void init() {
    l = strlen(s + 1);
    for (int i = 0; i <= l; ++i) {
      if (s[i] == 'A')
        sum[i] = sum[i - 1], a[i] = a[i - 1] + 1;
      else
        sum[i] = sum[i - 1] + 1, a[i] = 0;
    }
  }
} A, B;
int T;
int main() {
  scanf("%s%s", A.s + 1, B.s + 1);
  A.init();
  B.init();
  scanf("%d", &T);
  int lA, rA, lB, rB, t1, t2;
  while (T--) {
    scanf("%d%d%d%d", &lA, &rA, &lB, &rB);
    lA--;
    lB--;
    t1 = (B.sum[rB] - B.sum[lB]) - (A.sum[rA] - A.sum[lA]);
    t2 = min(rA - lA, A.a[rA]) - min(rB - lB, B.a[rB]);
    if (t2 < 0 || t1 < 0 || t1 & 1 || (t2 % 3 != 0 && t1 == 0) ||
        (t2 == 0 && rA - lA <= A.a[rA] && t1 != 0)) {
      printf("0");
    } else
      printf("1");
  }
}
