#include <bits/stdc++.h>
using namespace std;
string s, t;
int sa[100005], sb[100005];
int ta[100005], tb[100005];
int main() {
  cin >> s;
  int sl = s.length();
  for (int i = 0; i < sl; i++) {
    sb[i] = sb[i - 1] + (s[i] != 'A');
    if (s[i] == 'A') sa[i] = sa[i - 1] + 1;
  }
  cin >> t;
  int tl = t.length();
  for (int i = 0; i < tl; i++) {
    tb[i] = tb[i - 1] + (t[i] != 'A');
    if (t[i] == 'A') ta[i] = ta[i - 1] + 1;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a--, b--, c--, d--;
    int db = (tb[d] - tb[c - 1]) - (sb[b] - sb[a - 1]);
    int as = min(b - a + 1, sa[b]), at = min(d - c + 1, ta[d]);
    bool f = 1;
    if ((db & 1) || db < 0 || as < at) f = 0;
    if ((as - at) % 3 != 0 && db < 2) f = 0;
    if ((as - at) % 3 == 0 && db < 0) f = 0;
    if (sb[b] == sb[a - 1] && db && as == at) f = 0;
    printf("%d", f);
  }
  return 0;
}
