#include <bits/stdc++.h>
char a[100050], b[100050];
int sa[100050], sb[100050], ta[100050], tb[100050], Q;
int main() {
  scanf("%s%s", a + 1, b + 1);
  int la = strlen(a + 1), lb = strlen(b + 1);
  for (int i = 1; i <= la; i++) {
    if (a[i] == 'A') sa[i] = sa[i - 1] + 1;
    sb[i] = sb[i - 1] + (a[i] == 'B' || a[i] == 'C');
  }
  for (int i = 1; i <= lb; i++) {
    if (b[i] == 'A') ta[i] = ta[i - 1] + 1;
    tb[i] = tb[i - 1] + (b[i] == 'B' || b[i] == 'C');
  }
  int l, r, lsa, lta, ssb, stb;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &l, &r);
    lsa = std::min(r - l + 1, sa[r]), ssb = sb[r] - sb[l - 1];
    scanf("%d%d", &l, &r);
    lta = std::min(r - l + 1, ta[r]), stb = tb[r] - tb[l - 1];
    if (lsa < lta || ((ssb & 1) != (stb & 1)) || stb < ssb)
      printf("0");
    else if (lsa > lta && stb > ssb ||
             ((lsa - lta) % 3 == 0 && (ssb || (ssb == stb))))
      printf("1");
    else
      printf("0");
  }
}
