#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
const int MOD = 998244353;
const int INF = 1e9 + 10;
char s[MAXN];
char t[MAXN];
int sa[MAXN], sb[MAXN];
int ta[MAXN], tb[MAXN];
void fillab(char *s, int *a, int *b) {
  int n = strlen(s);
  a[0] = b[0] = 0;
  for (int i = 0; i < n; ++i) {
    a[i + 1] = (s[i] == 'A' ? a[i] + 1 : 0);
    b[i + 1] = b[i] + (s[i] == 'B' || s[i] == 'C' ? 1 : 0);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  scanf("%s", s);
  scanf("%s", t);
  fillab(s, sa, sb);
  fillab(t, ta, tb);
  int Q, ai, bi, ci, di;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d%d%d", &ai, &bi, &ci, &di);
    int san = min(sa[bi], bi - ai + 1), tan = min(ta[di], di - ci + 1);
    int sbn = sb[bi] - sb[ai - 1], tbn = tb[di] - tb[ci - 1];
    if (sbn > tbn || (sbn - tbn) % 2 != 0) {
      putchar('0');
    } else if (sbn == tbn) {
      putchar((san >= tan && (san - tan) % 3 == 0) ? '1' : '0');
    } else if (sbn != 0 && sbn < tbn) {
      putchar(san >= tan ? '1' : '0');
    } else if (sbn == 0) {
      putchar(san > tan ? '1' : '0');
    }
  }
  return 0;
}
