#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, q, sa[N], sb[N], ta[N], tb[N];
char s[N], t[N];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'A') sa[i] = sa[i - 1] + 1;
    sb[i] = sb[i - 1] + (s[i] != 'A');
  }
  scanf("%s", t + 1);
  m = strlen(t + 1);
  for (int i = 1; i <= m; i++) {
    if (t[i] == 'A') ta[i] = ta[i - 1] + 1;
    tb[i] = tb[i - 1] + (t[i] != 'A');
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int tmp = tb[d] - tb[c - 1] - (sb[b] - sb[a - 1]), res = 1;
    int cnt1 = min(sa[b], b - a + 1), cnt2 = min(ta[d], d - c + 1);
    bool flag = (cnt1 - cnt2) % 3 > 0;
    if (tmp < 0 || cnt1 < cnt2 || tmp % 2 == 1) res = 0;
    if (tmp - flag * 2 < 0) res = 0;
    if (sb[b] - sb[a - 1] == 0 && cnt1 == cnt2 && tmp) res = 0;
    printf("%d", res);
  }
  return 0;
}
