#include <bits/stdc++.h>
using namespace std;
class StringInfGetter {
 public:
  string &s;
  vector<int> a, b;
  int n;
  StringInfGetter(string &s1) : s(s1) {
    n = s.size();
    a.assign(n + 1, 0);
    b.assign(n + 1, 0);
    int anum = 0;
    for (int i = 0; i < int(n); i++) {
      anum = (s[i] == 'A' ? anum + 1 : 0);
      b[i + 1] = b[i] + (s[i] == 'B' || s[i] == 'C');
      a[i + 1] = anum;
    }
  }
  pair<int, int> getInf(int l, int r) {
    return make_pair((min(r - l + 1, a[r])), (b[r] - b[l - 1]));
  }
};
bool canConst(pair<int, int> a, pair<int, int> b) {
  if (a == b) return 1;
  if (b.second < a.second || ((b.second - a.second) % 2)) return 0;
  if (b.second > a.second)
    return (a.second ? a.first >= b.first : a.first > b.first);
  if (b.second == a.second)
    return a.first >= b.first && ((a.first - b.first) % 3) == 0;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  string s, t;
  cin >> s >> t;
  StringInfGetter a(s), b(t);
  int n;
  cin >> n;
  for (int i = 0; i < int(n); i++) {
    int l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    pair<int, int> p = a.getInf(l1, r1);
    pair<int, int> q = b.getInf(l2, r2);
    cout << canConst(p, q);
  }
}
