#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
string s, t;
int ns, nt;
int ps[maxn], pt[maxn];
int goods[maxn], goodt[maxn];
int ans[maxn];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  cin >> t;
  ns = s.length();
  nt = t.length();
  for (int i = (0); i < (ns); i++) {
    ps[i] = (i == 0) ? 0 : ps[i - 1];
    if (s[i] != 'A') ++ps[i];
  }
  for (int i = (0); i < (nt); i++) {
    pt[i] = (i == 0) ? 0 : pt[i - 1];
    if (t[i] != 'A') ++pt[i];
  }
  int la = -1;
  for (int i = (0); i < (ns); i++) {
    if (s[i] != 'A') la = i;
    goods[i] = la;
  }
  la = -1;
  for (int i = (0); i < (nt); i++) {
    if (t[i] != 'A') la = i;
    goodt[i] = la;
  }
  int q;
  cin >> q;
  for (int i = (0); i < (q); i++) {
    int ls, rs, lt, rt;
    cin >> ls >> rs >> lt >> rt;
    --ls;
    --rs;
    --lt;
    --rt;
    int cnts = ps[rs] - (ls == 0 ? 0 : ps[ls - 1]);
    int cntt = pt[rt] - (lt == 0 ? 0 : pt[lt - 1]);
    if (cnts > cntt) {
      ans[i] = 0;
      continue;
    }
    if (cnts % 2 != cntt % 2) {
      ans[i] = 0;
      continue;
    }
    int da = (cntt - cnts) / 2;
    int ss, st;
    ss = rs + 1 - max(ls, goods[rs]);
    st = rt + 1 - max(lt, goodt[rt]);
    bool can_make = false;
    if (ss >= st && (da >= 1 || (da == 0 && ss % 3 == st % 3))) can_make = true;
    if (can_make)
      ans[i] = 1;
    else
      ans[i] = 0;
  }
  for (int i = (0); i < (q); i++) cout << ans[i];
  return 0;
}
