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;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const int N = 100010;
int inf = 1e9;
int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  int n = (int)s.length();
  int m = (int)t.length();
  vector<int> xs(n + 1), xt(m + 1);
  vector<int> ones(n + 1), onet(m + 1);
  vector<int> zeros(n + 1), zerot(m + 1);
  xs[0] = xt[0] = 0;
  ones[0] = onet[0] = 0;
  zeros[0] = zerot[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'A') {
      xs[i] = xs[i - 1];
      ones[i] = ones[i - 1];
      zeros[i] = zeros[i - 1] + 1;
    } else {
      xs[i] = (xs[i - 1] ^ 1);
      ones[i] = ones[i - 1] + 1;
      zeros[i] = 0;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (t[i - 1] == 'A') {
      xt[i] = xt[i - 1];
      onet[i] = onet[i - 1];
      zerot[i] = zerot[i - 1] + 1;
    } else {
      xt[i] = (xt[i - 1] ^ 1);
      onet[i] = onet[i - 1] + 1;
      zerot[i] = 0;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((xs[b] ^ xs[a - 1]) != (xt[d] ^ xt[c - 1])) {
      cout << "0";
    } else {
      int z1 = min(b - a + 1, zeros[b]);
      int z2 = min(d - c + 1, zerot[d]);
      int o1 = ones[b] - ones[a - 1];
      int o2 = onet[d] - onet[c - 1];
      if (z1 < z2 || o1 > o2) {
        cout << "0";
        continue;
      }
      z1 -= z2;
      if (!z1 && !o1 && o2) {
        cout << "0";
        continue;
      }
      if (!o2) {
        if (z1 % 3 == 0) {
          cout << "1";
        } else {
          cout << "0";
        }
        continue;
      }
      if (z1 % 3 != 0 && o1 == o2) {
        cout << "0";
        continue;
      }
      cout << "1";
    }
  }
  cout << "\n";
  return 0;
}
