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>
const int _ML = 228;
const char _inpf[] = "";
const char _outf[] = "";
#pragma GCC optimize("O3,no-stack-protector")
using namespace std;
const double PI = 3.14159265358979323846;
mt19937 rd(228);
template <class T, class U>
inline ostream &operator<<(ostream &, const pair<T, U> &);
template <class T, class U>
inline istream &operator>>(istream &, pair<T, U> &);
template <class T>
inline ostream &operator<<(ostream &, const vector<T> &);
template <class T>
inline istream &operator>>(istream &, vector<T> &);
template <class T>
inline ostream &operator<<(ostream &, const set<T> &);
template <class T>
inline ostream &operator<<(ostream &, const multiset<T> &);
template <class T>
inline ostream &operator<<(ostream &, const unordered_set<T> &);
template <class T>
inline ostream &operator<<(ostream &, const unordered_multiset<T> &);
template <class T, class U>
inline ostream &operator<<(ostream &, const map<T, U> &);
template <class T, class U>
inline ostream &operator<<(ostream &, const unordered_map<T, U> &);
void prec(string s, vector<int> &a, vector<int> &b) {
  for (int i = 0; i < (int)(s).size(); ++i) {
    if (s[i] == 'B' || s[i] == 'C') {
      b[i] = 1;
    }
  }
  partial_sum((b).begin(), (b).end(), b.begin());
  for (int i = 0; i < (int)(s).size(); ++i) {
    if (i > 0) {
      a[i] = a[i - 1];
    }
    if (s[i] == 'A') {
      ++a[i];
    } else {
      a[i] = 0;
    }
  }
}
int get_t(vector<int> &v, int l, int r) {
  return v[r] - (l == 0 ? 0 : v[l - 1]);
}
inline void _main_function() {
  string s, t;
  cin >> s >> t;
  vector<int> sa((int)(s).size()), sb((int)(s).size()), ta((int)(t).size()),
      tb((int)(t).size());
  prec(s, sa, sb);
  prec(t, ta, tb);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int sl, sr, tl, tr;
    cin >> sl >> sr >> tl >> tr;
    --sl;
    --sr;
    --tl;
    --tr;
    int ssb = get_t(sb, sl, sr);
    int ssa = min(sa[sr], sr - sl + 1);
    int ttb = get_t(tb, tl, tr);
    int tta = min(ta[tr], tr - tl + 1);
    if (ssa < tta) {
      cout << 0;
      continue;
    } else if (ssb > ttb) {
      cout << 0;
      continue;
    } else if ((ttb - ssb) % 2 != 0) {
      cout << 0;
      continue;
    } else if ((ssa - tta) % 3 != 0 && ssb >= ttb) {
      cout << 0;
      continue;
    } else if (ssa == tta && ssb == 0 && ttb != 0) {
      cout << 0;
      continue;
    } else {
      cout << 1;
    }
  }
  cout << '\n';
}
int main() {
  if (_inpf[0] != '\0') assert(freopen(_inpf, "r", stdin) != nullptr);
  if (_outf[0] != '\0') assert(freopen(_outf, "w", stdout) != nullptr);
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << setprecision(20);
  _main_function();
}
template <class T, class U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.first << ' ' << _p.second;
  return _out;
}
template <class T, class U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <class T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << *_v.begin();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <class T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T, class U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
template <class T, class U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
