#include <bits/stdc++.h>
using namespace std;
int sa[100005], ta[100005], sb[100005], tb[100005];
char s[100005], t[100005];
int main() {
  int i, n, m, q, a, b, c, d, f, db, ss, tt;
  bool pd;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (i = 1; i <= n; i++) {
    sb[i] = sb[i - 1] + (s[i] != 'A');
    if (s[i] == 'A') sa[i] = sa[i - 1] + 1;
  }
  scanf("%s", t + 1);
  m = strlen(t + 1);
  for (i = 1; i <= m; i++) {
    tb[i] = tb[i - 1] + (t[i] != 'A');
    if (t[i] == 'A') ta[i] = ta[i - 1] + 1;
  }
  cin >> q;
  while (q--) {
    cin >> a >> b >> c >> d;
    f = 1;
    db = tb[d] - tb[c - 1] - (sb[b] - sb[a - 1]);
    ss = min(b - a + 1, sa[b]);
    tt = min(d - c + 1, ta[d]);
    if (db < 0 || ss < tt || db % 2 == 1) f = 0;
    pd = (ss - tt) % 3 > 0;
    if (db - pd * 2 < 0) f = 0;
    if (sb[b] - sb[a - 1] == 0 && db && ss == tt) f = 0;
    cout << f;
  }
  return 0;
}
