#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, q;
string s, t;
int sum_s[maxn], sum_t[maxn], a_s[maxn], a_t[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s >> t;
  n = s.size();
  m = t.size();
  for (int i = 0; i < n; i++) {
    sum_s[i + 1] = sum_s[i] + (s[i] != 'A');
    if (s[i] == 'A') {
      a_s[i + 1] = a_s[i] + 1;
    } else {
      a_s[i + 1] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    sum_t[i + 1] = sum_t[i] + (t[i] != 'A');
    if (t[i] == 'A') {
      a_t[i + 1] = a_t[i] + 1;
    } else {
      a_t[i + 1] = 0;
    }
  }
  cin >> q;
  for (int i = 0, a, b, c, d, ss, st, ls, lt, sfs, sft; i < q; i++) {
    cin >> a >> b >> c >> d;
    ss = (sum_s[b] - sum_s[a - 1]);
    st = (sum_t[d] - sum_t[c - 1]);
    ls = b - a + 1;
    lt = d - c + 1;
    sfs = min(a_s[b], ls);
    sft = min(a_t[d], lt);
    if (ss % 2 != st % 2) {
      cout << "0";
    } else {
      if (ss > st) {
        cout << "0";
      } else if (ss == st) {
        if (sfs >= sft && sfs % 3 == sft % 3) {
          cout << "1";
        } else {
          cout << "0";
        }
      } else {
        if (ss == 0 && st > 0 && sfs == sft) {
          cout << "0";
        } else if (sfs >= sft) {
          cout << "1";
        } else {
          cout << "0";
        }
      }
    }
  }
  cout << "\n";
  return 0;
}
