#include <bits/stdc++.h>
using namespace std;
int n, m, q;
char s[200011], t[200011];
int ms[200011], mt[200011], sums[200011], sumt[200011];
int main() {
  scanf("%s%s", s + 1, t + 1);
  n = strlen(s + 1);
  m = strlen(t + 1);
  for (int i = 1; i <= n; i++)
    sums[i] = sums[i - 1] + (s[i] != 'A'),
    ms[i] = s[i] == 'A' ? ms[i - 1] + 1 : 0;
  for (int i = 1; i <= m; i++)
    sumt[i] = sumt[i - 1] + (t[i] != 'A'),
    mt[i] = t[i] == 'A' ? mt[i - 1] + 1 : 0;
  scanf("%d", &q);
  while (q--) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int ss = sums[y1] - sums[x1 - 1], tt = sumt[y2] - sumt[x2 - 1];
    if (((ss & 1) ^ (tt & 1)) || ss > tt) {
      putchar('0');
      continue;
    }
    int aa = min(ms[y1], y1 - x1 + 1) - min(mt[y2], y2 - x2 + 1);
    if (aa < 0) {
      putchar('0');
      continue;
    }
    if (tt == ss) {
      if (aa % 3)
        putchar('0');
      else
        putchar('1');
    } else {
      if (aa || ss)
        putchar('1');
      else
        putchar('0');
    }
  }
  return 0;
}
