Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: 

  * A <image> BC
  * B <image> AC
  * C <image> AB
  * AAA <image> empty string 



Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source.

Input

The first line contains a string S (1 ≤ |S| ≤ 105). The second line contains a string T (1 ≤ |T| ≤ 105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'.

The third line contains the number of queries Q (1 ≤ Q ≤ 105).

The following Q lines describe queries. The i-th of these lines contains four space separated integers ai, bi, ci, di. These represent the i-th query: is it possible to create T[ci..di] from S[ai..bi] by applying the above transitions finite amount of times?

Here, U[x..y] is a substring of U that begins at index x (indexed from 1) and ends at index y. In particular, U[1..|U|] is the whole string U.

It is guaranteed that 1 ≤ a ≤ b ≤ |S| and 1 ≤ c ≤ d ≤ |T|.

Output

Print a string of Q characters, where the i-th character is '1' if the answer to the i-th query is positive, and '0' otherwise.

Example

Input

AABCCBAAB
ABCB
5
1 3 1 2
2 2 2 4
7 9 1 1
3 4 2 3
4 5 1 3


Output

10011

Note

In the first query we can achieve the result, for instance, by using transitions <image>.

The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 10000000000000000;
int MOD(int a, int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}
int max3(int a, int b, int c) { return max(c, max(a, b)); }
int min3(int a, int b, int c) { return min(a, min(b, c)); }
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
int logg(int a) {
  int x = 0;
  while (a > 1) {
    x++;
    a /= 2;
  }
  return x;
}
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int abso(int x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
long long int ceiling(long long int a, long long int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string second, t;
  cin >> second >> t;
  int q;
  cin >> q;
  vector<vector<int> > A(second.size());
  vector<vector<int> > B(t.size());
  for (int i = 0; i < second.size(); i++) {
    A[i].resize(3);
  }
  for (int i = 0; i < t.size(); i++) {
    B[i].resize(3);
  }
  for (int i = 0; i < second.size(); i++) {
    if (i == 0) {
      A[i][second[i] - 'A'] = 1;
    } else {
      A[i] = A[i - 1];
      A[i][second[i] - 'A'] = A[i - 1][second[i] - 'A'] + 1;
    }
  }
  vector<int> lenA(second.size());
  vector<int> lenB(t.size());
  for (int i = 0; i < second.size(); i++) {
    if (i == 0) {
      if (second[i] == 'A') {
        lenA[0] = 1;
      } else {
        lenA[0] = 0;
      }
    } else {
      if (second[i] == 'A') {
        lenA[i] = 1 + lenA[i - 1];
      } else {
        lenA[i] = 0;
      }
    }
  }
  for (int i = 0; i < t.size(); i++) {
    if (i == 0) {
      if (t[i] == 'A') {
        lenB[0] = 1;
      } else {
        lenB[0] = 0;
      }
    } else {
      if (t[i] == 'A') {
        lenB[i] = 1 + lenB[i - 1];
      } else {
        lenB[i] = 0;
      }
    }
  }
  for (int i = 0; i < t.size(); i++) {
    if (i == 0) {
      B[i][t[i] - 'A'] = 1;
    } else {
      B[i] = B[i - 1];
      B[i][t[i] - 'A'] = B[i - 1][t[i] - 'A'] + 1;
    }
  }
  while (q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    int num1 = A[b][1] + A[b][2];
    if (a > 0) {
      num1 -= (A[a - 1][1] + A[a - 1][2]);
    }
    int num2 = B[d][1] + B[d][2];
    if (c > 0) {
      num2 -= (B[c - 1][1] + B[c - 1][2]);
    }
    if (min(lenA[b], b - a + 1) >= min(lenB[d], d - c + 1)) {
      if ((min(lenA[b], b - a + 1) - min(lenB[d], d - c + 1)) == 0 &&
          (num1 == 0 && num2 != 0)) {
        cout << "0";
        continue;
      }
      if (((min(lenA[b], b - a + 1) - min(lenB[d], d - c + 1)) % 3 == 0)) {
        if ((num1 <= num2) && (num1 % 2 == num2 % 2)) {
          cout << "1";
        } else {
          cout << "0";
        }
      } else {
        if (((num1 + 2) <= (num2)) && (num2 % 2 == num1 % 2)) {
          cout << "1";
        } else {
          cout << "0";
        }
      }
    } else {
      cout << "0";
    }
  }
}
