#include <bits/stdc++.h>
using namespace std;
char txt[2][200000];
int A[2][100000], B[2][100000];
int check(int bs, int bt, int as, int at) {
  if ((bs - bt) % 2) return 0;
  if (bs > bt) return 0;
  if (bs > 0) {
    if (as == at) return 1;
    if (as < at) return 0;
    if (bs < bt) return 1;
    return (as - at) % 3 == 0;
  }
  if (bt == 0) return as >= at && (as - at) % 3 == 0;
  return as > at;
}
int main() {
  int i, j, q, u, v, w, x, AS, AT, BS, BT;
  scanf("%s%s", txt[0], txt[1]);
  for (i = 0; i <= 1; i++) {
    for (j = 0; txt[i][j]; j++) {
      if (txt[i][j] != 'A') {
        B[i][j] = 1 + (j == 0 ? 0 : B[i][j - 1]);
        A[i][j] = 0;
      } else {
        A[i][j] = 1 + (j == 0 ? 0 : A[i][j - 1]);
        B[i][j] = (j == 0 ? 0 : B[i][j - 1]);
      }
    }
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d%d%d", &u, &v, &w, &x);
    u--, v--, w--, x--;
    BS = B[0][v] - (u == 0 ? 0 : B[0][u - 1]);
    BT = B[1][x] - (w == 0 ? 0 : B[1][w - 1]);
    AS = min(A[0][v], v - u + 1);
    AT = min(A[1][x], x - w + 1);
    printf("%d", check(BS, BT, AS, AT));
  }
  printf("\n");
  return 0;
}
