#include <bits/stdc++.h>
template <class T>
void rd(T &k) {
  int f = 1;
  char c = getchar();
  k = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar();
  k *= f;
}
using namespace std;
const int N = 100005;
int n, m, k, s, t;
pair<int, int> k1, k2;
struct node {
  char c[N];
  int n, a[N], b[N];
  void init() {
    n = strlen(c + 1);
    for (register int i = 1; i <= n; ++i) {
      if (c[i] == 'C') c[i] = 'B';
      a[i] = a[i - 1];
      if (c[i] == 'B') ++a[i];
      if (c[i] == 'A')
        b[i] = b[i - 1] + 1;
      else
        b[i] = 0;
    }
  }
  pair<int, int> calc(int l, int r) {
    return {a[r] - a[l - 1], min(b[r], r - l + 1)};
  }
} T1, T2;
int main() {
  cin >> T1.c + 1 >> T2.c + 1;
  T1.init();
  T2.init();
  rd(n);
  for (register int i = 1; i <= n; ++i) {
    rd(s);
    rd(t);
    k1 = T1.calc(s, t);
    rd(s);
    rd(t);
    k2 = T2.calc(s, t);
    if (k2.second > k1.second)
      putchar('0');
    else {
      if (!k1.first && k2.first && (k1.second == k2.second)) {
        putchar('0');
        continue;
      }
      k1.first += ((k1.second - k2.second) % 3 > 0) * 2;
      if (k1.first <= k2.first && ((k1.first - k2.first) & 1) == 0)
        putchar('1');
      else
        putchar('0');
    }
  }
}
