#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:536870912")
#pragma warning(disable : 4996)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e5 + 100;
char s[N], t[N];
int ps[N], pt[N], es[N], et[N];
int main() {
  scanf(" %s %s", s, t);
  int ls = strlen(s), lt = strlen(t);
  int last = -1;
  for (int i = 0; i < ls; i++) {
    ps[i + 1] = ps[i];
    if (s[i] != 'A') {
      ps[i + 1]++;
      last = i;
    } else
      es[i + 1] = i - last;
  }
  last = -1;
  for (int i = 0; i < lt; i++) {
    pt[i + 1] = pt[i];
    if (t[i] != 'A') {
      pt[i + 1]++;
      last = i;
    } else
      et[i + 1] = i - last;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a--;
    c--;
    int ss = min(es[b], b - a), tt = min(et[d], d - c), x = ps[b] - ps[a],
        y = pt[d] - pt[c];
    if (x % 2 != y % 2 || x > y || ss < tt || x == 0 && y > 0 && ss - 1 < tt) {
      printf("0");
    } else if (ss % 3 == tt % 3 || x + 2 <= y) {
      printf("1");
    } else
      printf("0");
  }
  return 0;
}
