#include <bits/stdc++.h>
using namespace std;
int BS[100005];
int BT[100005];
char S[100005];
char T[100005];
int SN, TN;
int ans[100005];
int AS[100005];
int AT[100005];
int main() {
  scanf(" %s", S + 1);
  scanf(" %s", T + 1);
  SN = (int)strlen(S + 1);
  TN = (int)strlen(T + 1);
  S[0] = T[0] = 0;
  for (int i = 1; i <= SN; i++) {
    BS[i] = BS[i - 1];
    if (S[i] == 'B' || S[i] == 'C') BS[i]++;
  }
  for (int i = 1; i <= TN; i++) {
    BT[i] = BT[i - 1];
    if (T[i] == 'B' || T[i] == 'C') BT[i]++;
  }
  for (int i = 1; i <= SN; i++) {
    if (S[i] != 'A')
      AS[i] = 0;
    else
      AS[i] = AS[i - 1] + 1;
  }
  for (int i = 1; i <= TN; i++) {
    if (T[i] != 'A')
      AT[i] = 0;
    else
      AT[i] = AT[i - 1] + 1;
  }
  int Q;
  scanf("%d", &Q);
  for (int q = 0; q < Q; q++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int scnt = BS[b] - BS[a - 1];
    int tcnt = BT[d] - BT[c - 1];
    if (scnt > tcnt) {
      ans[q] = 0;
      continue;
    }
    if (scnt % 2 != tcnt % 2) {
      ans[q] = 0;
      continue;
    }
    int x = min(b - a + 1, AS[b]), y = min(d - c + 1, AT[d]);
    if (x < y) {
      ans[q] = 0;
      continue;
    }
    if (x > y && (x - y) % 3 && scnt + 2 > tcnt) {
      ans[q] = 0;
      continue;
    }
    if (x == y && x == b - a + 1 && y != d - c + 1) {
      ans[q] = 0;
      continue;
    }
    ans[q] = 1;
  }
  for (int i = 0; i < Q; i++) printf("%d", ans[i]);
  return 0;
}
