#include <bits/stdc++.h>
using namespace std;
int N, L, i, j, SA[100005], SB[100005], TA[100005], TB[100005], X, Y, Saa, Sbc,
    Taa, Tbc;
bool B;
char C[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> C;
  L = strlen(C);
  for (i = 1; i <= L; i++) {
    SB[i] = SB[i - 1];
    if (C[i - 1] == 'A') {
      SA[i] = SA[i - 1] + 1;
    } else {
      SB[i]++;
    }
  }
  cin >> C;
  L = strlen(C);
  for (i = 1; i <= L; i++) {
    TB[i] = TB[i - 1];
    if (C[i - 1] == 'A') {
      TA[i] = TA[i - 1] + 1;
    } else {
      TB[i]++;
    }
  }
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> X >> Y;
    Saa = min(Y - X + 1, SA[Y]);
    Sbc = SB[Y] - SB[X - 1];
    cin >> X >> Y;
    Taa = min(Y - X + 1, TA[Y]);
    Tbc = TB[Y] - TB[X - 1];
    B = 0;
    if (Sbc == 0 && Tbc != 0) {
      if (Tbc % 2 == 0 && Saa - Taa >= 1) {
        B = 1;
      }
    } else if (Saa >= Taa) {
      if (Sbc < Tbc) {
        if ((Tbc - Sbc) % 2 == 0) {
          B = 1;
        }
      }
      if (Sbc == Tbc) {
        if ((Saa - Taa) % 3 == 0) {
          B = 1;
        }
      }
    }
    cout << B;
  }
}
