#include <bits/stdc++.h>
using namespace std;
char s[100005], t[100005];
int fa[100005], sb[100005], sc[100005], tb[100005], tc[100005], ia[100005];
int res[100005];
int main() {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  int n = strlen(s + 1);
  int m = strlen(t + 1);
  for (int i = 1; i <= n; ++i) {
    fa[i] = fa[i - 1] + (s[i] == 'A');
    if (s[i] != 'A') fa[i] = 0;
    sb[i] = sb[i - 1] + (s[i] == 'B');
    sc[i] = sc[i - 1] + (s[i] == 'C');
  }
  for (int i = 1; i <= m; ++i) {
    ia[i] = ia[i - 1] + (t[i] == 'A');
    if (t[i] != 'A') ia[i] = 0;
    tb[i] = tb[i - 1] + (t[i] == 'B');
    tc[i] = tc[i - 1] + (t[i] == 'C');
  }
  int Q;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) {
    int l, r, ll, rr;
    scanf("%d%d%d%d", &l, &r, &ll, &rr);
    int Sb = sb[r] - sb[l - 1];
    int Sc = sc[r] - sc[l - 1];
    int Tb = tb[rr] - tb[ll - 1];
    int Tc = tc[rr] - tc[ll - 1];
    Sb += Sc;
    Tb += Tc;
    int L = fa[r], R = ia[rr];
    if (L - fa[l - 1] == r - l + 1) L = r - l + 1;
    if (R - ia[ll - 1] == rr - ll + 1) R = rr - ll + 1;
    if (R > L) {
      res[i] = 0;
      continue;
    }
    if ((L - R) % 3 != 0 && L > R) Sb += 2;
    if (L == R && Sb == 0 && Tb) {
      res[i] = 0;
      continue;
    }
    if ((Sb % 2) ^ (Tb % 2) == 1 || Tb < Sb)
      res[i] = 0;
    else
      res[i] = 1;
  }
  for (int i = 1; i <= Q; ++i) printf("%d", res[i]);
  return 0;
}
