#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, s1[100007] = {0}, s2[100007] = {0}, t1[100007] = {0},
                   t2[100007] = {0};
string m, n;
int main() {
  cin >> m >> n;
  for (int i = 1; i <= m.size(); i++) {
    if (m[i - 1] == 'B' || m[i - 1] == 'C') s1[i] = 1;
    s1[i] += s1[i - 1];
  }
  for (int i = 1; i <= n.size(); i++) {
    if (n[i - 1] == 'B' || n[i - 1] == 'C') t1[i] = 1;
    t1[i] += t1[i - 1];
  }
  for (int i = 1; i <= m.size(); i++) {
    if (m[i - 1] == 'A')
      s2[i] = s2[i - 1] + 1;
    else
      s2[i] = 0;
  }
  for (int i = 1; i <= n.size(); i++)
    if (n[i - 1] == 'A')
      t2[i] = t2[i - 1] + 1;
    else
      t2[i] = 0;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    cin >> b >> c >> d >> e;
    int l = (t1[e] - t1[d - 1] - s1[c] + s1[b - 1]);
    int r1 = s2[c];
    if (r1 > c - b + 1) r1 = c - b + 1;
    int r2 = t2[e];
    if (r2 > e - d + 1) r2 = e - d + 1;
    if (r1 == c - b + 1 && l > 0) r1--;
    if (l >= 0 && l % 2 == 0)
      if (r1 >= r2 && (r1 % 3 == r2 % 3 || l >= 2)) {
        cout << 1;
        continue;
      }
    cout << 0;
  }
}
