#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
#include <climits>
#include <map>
#include <iterator>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
#define nfor(i, x, y) for (int i = x; i < y; i++)
#define forn(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
#define g(n, t) get<n>(t)

const long long mod = (long long)1e9 + 7;
const int maxn = (int)2e3 + 1;
long long inf = 1LL << 60;
const double eps = 1e-9;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, bool> mib;
typedef pair<ll, ll> pll;
typedef pair<int, bool> pib;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector <pii> vpii;

template <class N>
inline void read(N &n)
{
	N x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = 10 * x + ch - '0'; ch = getchar(); }
	n = x*f;
}

//void dfs(int v){
//	used[v] = true;
//	for (int i = 0; i < a.size(); i++){
//		if (!used[a[v][i]]){
//			dfs(a[v][i]);
//		}
//	}
//}

int main()
{
	srand(time(0));
	ios_base::sync_with_stdio(0);
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	vi q(8);
	vector <string> s;
	nfor(i, 0, n){
		int a;
		cin >> a;
		q[a]++;
	}

	if (q[5] != 0 || q[7] != 0){
		cout << -1;
		return 0;
	}
	while (q[1] && q[2] && q[4] || q[1] && q[2] && q[6] || q[1] && q[3] && q[6]){
		if (q[1] > 0 && q[2] > 0 && q[4] > 0){
			s.push_back("1 2 4");
			q[1]--;
			q[2]--;
			q[4]--;
		}
		if (q[1] > 0 && q[3] > 0 && q[6] > 0){
			s.push_back("1 3 6");
			q[1]--;
			q[3]--;
			q[6]--;
		}
		if (q[1] > 0 && q[2] > 0 && q[6] > 0){
			s.push_back("1 2 6");
			q[1]--;
			q[2]--;
			q[6]--;
		}
	}
	if (s.empty() || q[1] || q[2] || q[4] || q[6]|| q[3]){
		cout << -1;
		return 0;
	}

	nfor(i, 0, s.size()){
		cout << s[i] << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
#include <climits>
#include <map>
#include <iterator>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
#define nfor(i, x, y) for (int i = x; i < y; i++)
#define forn(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
#define g(n, t) get<n>(t)

const long long mod = (long long)1e9 + 7;
const int maxn = (int)2e3 + 1;
long long inf = 1LL << 60;
const double eps = 1e-9;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, bool> mib;
typedef pair<ll, ll> pll;
typedef pair<int, bool> pib;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector <pii> vpii;

template <class N>
inline void read(N &n)
{
	N x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = 10 * x + ch - '0'; ch = getchar(); }
	n = x*f;
}

//void dfs(int v){
//	used[v] = true;
//	for (int i = 0; i < a.size(); i++){
//		if (!used[a[v][i]]){
//			dfs(a[v][i]);
//		}
//	}
//}

int main()
{
	srand(time(0));
	ios_base::sync_with_stdio(0);
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	vi q(8);
	vector <string> s;
	nfor(i, 0, n){
		int a;
		cin >> a;
		q[a]++;
	}

	if (q[5] != 0 || q[7] != 0){
		cout << -1;
		return 0;
	}
	while (q[1] && q[2] && q[4] || q[1] && q[2] && q[6] || q[1] && q[3] && q[6]){
		if (q[1] > 0 && q[3] > 0 && q[6] > 0){
			s.push_back("1 3 6");
			q[1]--;
			q[3]--;
			q[6]--;
			continue;
		}
		if (q[1] > 0 && q[2] > 0 && q[6] > 0){
			s.push_back("1 2 6");
			q[1]--;
			q[2]--;
			q[6]--;
			continue;
		}
		if (q[1] > 0 && q[2] > 0 && q[4] > 0){
			s.push_back("1 2 4");
			q[1]--;
			q[2]--;
			q[4]--;
			continue;
		}
	}
	if (s.empty() || q[1] || q[2] || q[3] || q[4] || q[6]){
		cout << -1;
		return 0;
	}

	nfor(i, 0, s.size()){
		cout << s[i] << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
#include <climits>
#include <map>
#include <iterator>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
#define nfor(i, x, y) for (int i = x; i < y; i++)
#define forn(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
#define g(n, t) get<n>(t)

const long long mod = (long long)1e9 + 7;
const int maxn = (int)2e3 + 1;
long long inf = 1LL << 60;
const double eps = 1e-9;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, bool> mib;
typedef pair<ll, ll> pll;
typedef pair<int, bool> pib;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector <pii> vpii;

template <class N>
inline void read(N &n)
{
	N x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = 10 * x + ch - '0'; ch = getchar(); }
	n = x*f;
}

//void dfs(int v){
//	used[v] = true;
//	for (int i = 0; i < a.size(); i++){
//		if (!used[a[v][i]]){
//			dfs(a[v][i]);
//		}
//	}
//}

int main()
{
	srand(time(0));
	ios_base::sync_with_stdio(0);
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	vi q(8);
	vector <string> s;
	nfor(i, 0, n){
		int a;
		cin >> a;
		q[a]++;
	}

	if (q[5] != 0 || q[7] != 0){
		cout << -1;
		return 0;
	}
	while (q[1] && q[2] && q[4] || q[1] && q[2] && q[6] || q[1] && q[3] && q[6]){
		if (q[1] > 0 && q[2] > 0 && q[6] > 0){
			s.push_back("1 2 6");
			q[1]--;
			q[2]--;
			q[6]--;
			continue;
		}
		if (q[1] > 0 && q[2] > 0 && q[4] > 0){
			s.push_back("1 2 4");
			q[1]--;
			q[2]--;
			q[4]--;
			continue;
		}
		if (q[1] > 0 && q[3] > 0 && q[6] > 0){
			s.push_back("1 3 6");
			q[1]--;
			q[3]--;
			q[6]--;
			continue;
		}
	}
	if (s.empty() || q[1] || q[2] || q[3] || q[4] || q[6]){
		cout << -1;
		return 0;
	}

	nfor(i, 0, s.size()){
		cout << s[i] << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
#include <climits>
#include <map>
#include <iterator>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
#define nfor(i, x, y) for (int i = x; i < y; i++)
#define forn(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
#define g(n, t) get<n>(t)

const long long mod = (long long)1e9 + 7;
const int maxn = (int)2e3 + 1;
long long inf = 1LL << 60;
const double eps = 1e-9;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, bool> mib;
typedef pair<ll, ll> pll;
typedef pair<int, bool> pib;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector <pii> vpii;

template <class N>
inline void read(N &n)
{
	N x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = 10 * x + ch - '0'; ch = getchar(); }
	n = x*f;
}

//void dfs(int v){
//	used[v] = true;
//	for (int i = 0; i < a.size(); i++){
//		if (!used[a[v][i]]){
//			dfs(a[v][i]);
//		}
//	}
//}

int main()
{
	srand(time(0));
	ios_base::sync_with_stdio(0);
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;

	cin >> n;
	vi q(8);
	vector <string> s;
	nfor(i, 0, n){
		int a;
		cin >> a;
		q[a]++;
	}

	if (q[5] != 0 || q[7] != 0){
		cout << -1;
		return 0;
	}
	while (q[1] && q[2] && q[4] || q[1] && q[2] && q[6] || q[1] && q[3] && q[6]){
		if (q[1] > 0 && q[2] > 0 && q[4] > 0){
			s.push_back("1 2 4");
			q[1]--, q[2]--, q[4]--;
		}
		if (q[1] > 0 && q[3] > 0 && q[6] > 0){
			s.push_back("1 3 6");
			q[1]--, q[3]--, q[6]--;
		}
		if (q[1] > 0 && q[2] > 0 && q[6] > 0){
			s.push_back("1 2 6");
			q[1]--, q[2]--, q[6]--;
		}
	}
	if (s.empty() || q[1] || q[2] || q[4] || q[6]){
		cout << -1;
		return 0;
	}

	nfor(i, 0, s.size()){
		cout << s[i] << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
#include <climits>
#include <map>
#include <iterator>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
#define nfor(i, x, y) for (int i = x; i < y; i++)
#define forn(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
#define g(n, t) get<n>(t)

const long long mod = (long long)1e9 + 7;
const int maxn = (int)2e3 + 1;
long long inf = 1LL << 60;
const double eps = 1e-9;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, bool> mib;
typedef pair<ll, ll> pll;
typedef pair<int, bool> pib;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector <pii> vpii;

template <class N>
inline void read(N &n)
{
	N x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = 10 * x + ch - '0'; ch = getchar(); }
	n = x*f;
}

//void dfs(int v){
//	used[v] = true;
//	for (int i = 0; i < a.size(); i++){
//		if (!used[a[v][i]]){
//			dfs(a[v][i]);
//		}
//	}
//}

int main()
{
	srand(time(0));
	ios_base::sync_with_stdio(0);
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;

	cin >> n;
	vi q(8);
	vector <string> s;
	nfor(i, 0, n){
		int a;
		cin >> a;
		q[a]++;
	}

	if (q[5] != 0 || q[7] != 0){
		cout << -1;
		return 0;
	}
	while (q[1] && q[2] && q[4] || q[1] && q[2] && q[6] || q[1] && q[3] && q[6]){
		if (q[1] > 0 && q[2] > 0 && q[4] > 0){
			s.push_back("1 2 4");
			q[1]--, q[2]--, q[3]--;
		}
		if (q[1] > 0 && q[3] > 0 && q[6] > 0){
			s.push_back("1 3 6");
			q[1]--, q[3]--, q[6]--;
		}
		if (q[1] > 0 && q[2] > 0 && q[6] > 0){
			s.push_back("1 2 6");
			q[1]--, q[2]--, q[6]--;
		}
	}
	if (s.empty()){
		cout << -1;
		return 0;
	}

	nfor(i, 0, s.size()){
		cout << s[i] << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
#include <climits>
#include <map>
#include <iterator>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
#define nfor(i, x, y) for (int i = x; i < y; i++)
#define forn(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
#define g(n, t) get<n>(t)

const long long mod = (long long)1e9 + 7;
const int maxn = (int)2e3 + 1;
long long inf = 1LL << 60;
const double eps = 1e-9;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, bool> mib;
typedef pair<ll, ll> pll;
typedef pair<int, bool> pib;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector <pii> vpii;

template <class N>
inline void read(N &n)
{
	N x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = 10 * x + ch - '0'; ch = getchar(); }
	n = x*f;
}

//void dfs(int v){
//	used[v] = true;
//	for (int i = 0; i < a.size(); i++){
//		if (!used[a[v][i]]){
//			dfs(a[v][i]);
//		}
//	}
//}

int main()
{
	srand(time(0));
	ios_base::sync_with_stdio(0);
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;

	cin >> n;
	vi q(8);
	vector <string> s;
	nfor(i, 0, n){
		int a;
		cin >> a;
		q[a]++;
	}

	if (q[5] != 0 || q[7] != 0){
		cout << -1;
		return 0;
	}
	while (q[1] && q[2] && q[4] || q[1] && q[2] && q[6] || q[1] && q[3] && q[6]){
		if (q[1] > 0 && q[2] > 0 && q[4] > 0){
			s.push_back("1 2 4");
			q[1]--, q[2]--, q[3]--;
		}
		if (q[1] > 0 && q[3] > 0 && q[6] > 0){
			s.push_back("1 3 6");
			q[1]--, q[3]--, q[6]--;
		}
		if (q[1] > 0 && q[2] > 0 && q[6] > 0){
			s.push_back("1 2 6");
			q[1]--, q[2]--, q[6]--;
		}
	}
	if (s.empty()){
		cout << -1;
		return 0;
	}
	cout << s.size() << endl;
	nfor(i, 0, s.size()){
		cout << s[i] << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
#include <climits>
#include <map>
#include <iterator>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
#define nfor(i, x, y) for (int i = x; i < y; i++)
#define forn(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
#define g(n, t) get<n>(t)

const long long mod = (long long)1e9 + 7;
const int maxn = (int)2e3 + 1;
long long inf = 1LL << 60;
const double eps = 1e-9;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, bool> mib;
typedef pair<ll, ll> pll;
typedef pair<int, bool> pib;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector <pii> vpii;

template <class N>
inline void read(N &n)
{
	N x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = 10 * x + ch - '0'; ch = getchar(); }
	n = x*f;
}

//void dfs(int v){
//	used[v] = true;
//	for (int i = 0; i < a.size(); i++){
//		if (!used[a[v][i]]){
//			dfs(a[v][i]);
//		}
//	}
//}

int main()
{
	srand(time(0));
	ios_base::sync_with_stdio(0);
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;

	cin >> n;
	vi q(8);
	vector <string> s;
	nfor(i, 0, n){
		int a;
		cin >> a;
		q[a]++;
	}

	if (q[5] != 0 || q[7] != 0){
		cout << -1;
		return 0;
	}
	while (q[1] && q[2] && q[4] || q[1] && q[2] && q[6] || q[1] && q[3] && q[6]){
		if (q[1] > 0 && q[2] > 0 && q[4] > 0){
			s.push_back("1 2 4");
			q[1]--, q[2]--, q[4]--;
		}
		if (q[1] > 0 && q[3] > 0 && q[6] > 0){
			s.push_back("1 3 6");
			q[1]--, q[3]--, q[6]--;
		}
		if (q[1] > 0 && q[2] > 0 && q[6] > 0){
			s.push_back("1 2 6");
			q[1]--, q[2]--, q[6]--;
		}
	}
	if (s.empty()){
		cout << -1;
		return 0;
	}

	nfor(i, 0, s.size()){
		cout << s[i] << endl;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#define min(a,b) ((a)<(b)?(a):(b))
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxN=1e5+10;
char s[maxN],t[maxN];
int i,a[maxN],b[maxN],n,q,m,x,y,l,r,ans,ss[maxN],st[maxN],
lass[maxN],last[maxN],s0,t0,s1,t1;
void Y(){
	printf("1");
}
void N(){
	printf("0");
}
int main(){
	freopen("a.in","r",stdin);
	scanf("%s\n",s+1),n=strlen(s+1);
	scanf("%s\n",t+1),m=strlen(t+1);
	fo(i,1,n)
		a[i]=(s[i]=='A')?0:1;
	fo(i,1,n) ss[i]=ss[i-1]+a[i],lass[i]=(a[i])?0:lass[i-1]+1;
	fo(i,1,m) b[i]=(t[i]=='A')?0:1;
	fo(i,1,m) st[i]=st[i-1]+b[i],last[i]=(b[i])?0:last[i-1]+1;
	for(scanf("%d",&q);q;q--){
		scanf("%d%d%d%d",&x,&y,&l,&r);
		s0=min(lass[y],y-x+1),s1=ss[y]-ss[x-1],
		t0=min(last[r],r-l+1),t1=st[r]-st[l-1];
		if (s1>t1) {N();continue;}
		if (s0<t0) {N();continue;}
		if ((s1&1)!=(t1&1)){N();continue;}
		if (s0==t0){
			if (t1 && !s1){N();continue;}
		}
		if (s0>t0){
			if (s1==t1 && (s0-t0)%3!=0)  {N();continue;}
		}
		Y();
	}
}


#include <cstdio>
#include <cstring>
#include <iostream>
#define min(a,b) ((a)<(b)?(a):(b))
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxN=1e5+10;
char s[maxN],t[maxN];
int i,a[maxN],b[maxN],n,q,m,x,y,l,r,ans,ss[maxN],st[maxN],
lass[maxN],last[maxN],s0,t0,s1,t1;
void Y(){
	printf("1");
}
void N(){
	printf("0");
}
int main(){
	//freopen("a.in","r",stdin);
	scanf("%s\n",s+1),n=strlen(s+1);
	scanf("%s\n",t+1),m=strlen(t+1);
	fo(i,1,n)
		a[i]=(s[i]=='A')?0:1;
	fo(i,1,n) ss[i]=ss[i-1]+a[i],lass[i]=(a[i])?0:lass[i-1]+1;
	fo(i,1,m) b[i]=(t[i]=='A')?0:1;
	fo(i,1,m) st[i]=st[i-1]+b[i],last[i]=(b[i])?0:last[i-1]+1;
	for(scanf("%d",&q);q;q--){
		scanf("%d%d%d%d",&x,&y,&l,&r);
		s0=min(lass[y],y-x+1),s1=ss[y]-ss[x-1],
		t0=min(last[r],r-l+1),t1=st[r]-st[l-1];
		if (s1>t1) {N();continue;}
		if (s0<t0) {N();continue;}
		if ((s1&1)!=(t1&1)){N();continue;}
		if (s0==t0){
			if (t1 && !s1){N();continue;}
		}
		if (s0>t0){
			if (s1==t1 && (s0-t0)%3!=0)  {N();continue;}
		}
		Y();
	}
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
char s[100003],t[100003];
int slen,tlen;
int sa[100003],sb[100003],ta[100003],tb[100003];
int main()
{
	scanf("%s%s",s+1,t+1);
	slen=strlen(s+1);
	for (int i=1;i<=slen;++i)
		if (s[i]=='A')
		{
			sa[i]=sa[i-1]+1;
			sb[i]=sb[i-1];
		}
		else
		{
			sa[i]=0;
			sb[i]=sb[i-1]+1;
		}
	tlen=strlen(t+1);
	for (int i=1;i<=tlen;++i)
		if (t[i]=='A')
		{
			ta[i]=ta[i-1]+1;
			tb[i]=tb[i-1];
		}
		else
		{
			ta[i]=0;
			tb[i]=tb[i-1]+1;
		}
	int Q;
	scanf("%d",&Q);
	while (Q--)
	{
		int ls,rs,lt,rt;
		scanf("%d%d%d%d",&ls,&rs,&lt,&rt);
		int s1=sb[rs]-sb[ls-1],t1=tb[rt]-tb[lt-1];
		int s0=min(sa[rs],rs-ls+1),t0=min(ta[rt],rt-lt+1);
		if (s1>t1 || s1==t1 && s0 && !t0 || (s1&1)!=(t1&1))
			putchar('0');
		else
		{
			if (!s1 && t1)
			{
				if (s0==t0)
					putchar('0');
				else
					putchar('1');
			}
			else if (s0<t0 || s0 && t0 && s0%3!=t0%3)
				putchar('0');
			else
				putchar('1');
		}
	}
	return 0;
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
char s[100003],t[100003];
int slen,tlen;
int sa[100003],sb[100003],ta[100003],tb[100003];
int main()
{
	scanf("%s%s",s+1,t+1);
	slen=strlen(s+1);
	for (int i=1;i<=slen;++i)
		if (s[i]=='A')
		{
			sa[i]=sa[i-1]+1;
			sb[i]=sb[i-1];
		}
		else
		{
			sa[i]=0;
			sb[i]=sb[i-1]+1;
		}
	tlen=strlen(t+1);
	for (int i=1;i<=tlen;++i)
		if (t[i]=='A')
		{
			ta[i]=ta[i-1]+1;
			tb[i]=tb[i-1];
		}
		else
		{
			ta[i]=0;
			tb[i]=tb[i-1]+1;
		}
	int Q;
	scanf("%d",&Q);
	while (Q--)
	{
		int ls,rs,lt,rt;
		scanf("%d%d%d%d",&ls,&rs,&lt,&rt);
		int s1=sb[rs]-sb[ls-1],t1=tb[rt]-tb[lt-1];
		if (s1>t1 || (s1&1)!=(t1&1))
			putchar('0');
		else
		{
			int s0=min(sa[rs],rs-ls+1),t0=min(ta[rt],rt-lt+1);
			if (s0<t0 || s0%3!=t0%3)
				putchar('0');
			else
				putchar('1');
		}
	}
	return 0;
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
char s[100003],t[100003];
int slen,tlen;
int sa[100003],sb[100003],ta[100003],tb[100003];
int main()
{
	scanf("%s%s",s+1,t+1);
	slen=strlen(s+1);
	for (int i=1;i<=slen;++i)
		if (s[i]=='A')
		{
			sa[i]=sa[i-1]+1;
			sb[i]=sb[i-1];
		}
		else
		{
			sa[i]=0;
			sb[i]=sb[i-1]+1;
		}
	tlen=strlen(t+1);
	for (int i=1;i<=tlen;++i)
		if (t[i]=='A')
		{
			ta[i]=ta[i-1]+1;
			tb[i]=tb[i-1];
		}
		else
		{
			ta[i]=0;
			tb[i]=tb[i-1]+1;
		}
	int Q;
	scanf("%d",&Q);
	while (Q--)
	{
		int ls,rs,lt,rt;
		scanf("%d%d%d%d",&ls,&rs,&lt,&rt);
		int s1=sb[rs]-sb[ls-1],t1=tb[rt]-tb[lt-1],s0=min(sa[rs],rs-ls+1),t0=min(ta[rt],rt-lt+1);
		if ((s1&1)==(t1&1) && s0>=t0 && s1+(s0-t0)%3*2<=t1)
			putchar('1');
		else
			putchar('0');
	}
	return 0;
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
char s[100003],t[100003];
int slen,tlen;
int sa[100003],sb[100003],ta[100003],tb[100003];
int main()
{
	scanf("%s%s",s+1,t+1);
	slen=strlen(s+1);
	for (int i=1;i<=slen;++i)
		if (s[i]=='A')
		{
			sa[i]=sa[i-1]+1;
			sb[i]=sb[i-1];
		}
		else
		{
			sa[i]=0;
			sb[i]=sb[i-1]+1;
		}
	tlen=strlen(t+1);
	for (int i=1;i<=tlen;++i)
		if (t[i]=='A')
		{
			ta[i]=ta[i-1]+1;
			tb[i]=tb[i-1];
		}
		else
		{
			ta[i]=0;
			tb[i]=tb[i-1]+1;
		}
	int Q;
	scanf("%d",&Q);
	while (Q--)
	{
		int ls,rs,lt,rt;
		scanf("%d%d%d%d",&ls,&rs,&lt,&rt);
		int s1=sb[rs]-sb[ls-1],t1=tb[rt]-tb[lt-1];
		if (s1>t1 || !s1 && t1 || (s1&1)!=(t1&1))
			putchar('0');
		else
		{
			int s0=min(sa[rs],rs-ls+1),t0=min(ta[rt],rt-lt+1);
			if (s0<t0 || s0%3!=t0%3)
				putchar('0');
			else
				putchar('1');
		}
	}
	return 0;
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
char s[100003],t[100003];
int slen,tlen;
int sa[100003],sb[100003],ta[100003],tb[100003];
int main()
{
	scanf("%s%s",s+1,t+1);
	slen=strlen(s+1);
	for (int i=1;i<=slen;++i)
		if (s[i]=='A')
		{
			sa[i]=sa[i-1]+1;
			sb[i]=sb[i-1];
		}
		else
		{
			sa[i]=0;
			sb[i]=sb[i-1]+1;
		}
	tlen=strlen(t+1);
	for (int i=1;i<=tlen;++i)
		if (t[i]=='A')
		{
			ta[i]=ta[i-1]+1;
			tb[i]=tb[i-1];
		}
		else
		{
			ta[i]=0;
			tb[i]=tb[i-1]+1;
		}
	int Q;
	scanf("%d",&Q);
	while (Q--)
	{
		int ls,rs,lt,rt;
		scanf("%d%d%d%d",&ls,&rs,&lt,&rt);
		int s1=sb[rs]-sb[ls-1],t1=tb[rt]-tb[lt-1];
		if (s1>t1 || (s1&1)!=(t1&1))
			putchar('0');
		else
		{
			int s0=min(sa[rs],rs-ls+1),t0=min(ta[rt],rt-lt+1);
			if (!s1 && t1)
			{
				if ((s0+2)%3!=t0%3)
					putchar('0');
				else
					putchar('1');
			}
			else if (s0<t0 || s0%3!=t0%3)
				putchar('0');
			else
				putchar('1');
		}
	}
	return 0;
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
char s[100003],t[100003];
int slen,tlen;
int sa[100003],sb[100003],ta[100003],tb[100003];
int main()
{
	scanf("%s%s",s+1,t+1);
	slen=strlen(s+1);
	for (int i=1;i<=slen;++i)
		if (s[i]=='A')
		{
			sa[i]=sa[i-1]+1;
			sb[i]=sb[i-1];
		}
		else
		{
			sa[i]=0;
			sb[i]=sb[i-1]+1;
		}
	tlen=strlen(t+1);
	for (int i=1;i<=tlen;++i)
		if (t[i]=='A')
		{
			ta[i]=ta[i-1]+1;
			tb[i]=tb[i-1];
		}
		else
		{
			ta[i]=0;
			tb[i]=tb[i-1]+1;
		}
	int Q;
	scanf("%d",&Q);
	while (Q--)
	{
		int ls,rs,lt,rt;
		scanf("%d%d%d%d",&ls,&rs,&lt,&rt);
		int s1=sb[rs]-sb[ls-1],t1=tb[rt]-tb[lt-1];
		if (s1>t1 || (s1&1)!=(t1&1))
			putchar('0');
		else
		{
			int s0=min(sa[rs],rs-ls+1),t0=min(ta[rt],rt-lt+1);
			if (s0<t0 || !s1 && t1 && s0==t0 || s0%3!=t0%3)
				putchar('0');
			else
				putchar('1');
		}
	}
	return 0;
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
char s[100003],t[100003];
int slen,tlen;
int sa[100003],sb[100003],ta[100003],tb[100003];
int main()
{
	scanf("%s%s",s+1,t+1);
	slen=strlen(s+1);
	for (int i=1;i<=slen;++i)
		if (s[i]=='A')
		{
			sa[i]=sa[i-1]+1;
			sb[i]=sb[i-1];
		}
		else
		{
			sa[i]=0;
			sb[i]=sb[i-1]+1;
		}
	tlen=strlen(t+1);
	for (int i=1;i<=tlen;++i)
		if (t[i]=='A')
		{
			ta[i]=ta[i-1]+1;
			tb[i]=tb[i-1];
		}
		else
		{
			ta[i]=0;
			tb[i]=tb[i-1]+1;
		}
	int Q;
	scanf("%d",&Q);
	while (Q--)
	{
		int ls,rs,lt,rt;
		scanf("%d%d%d%d",&ls,&rs,&lt,&rt);
		int s1=sb[rs]-sb[ls-1],t1=tb[rt]-tb[lt-1];
		int s0=min(sa[rs],rs-ls+1),t0=min(ta[rt],rt-lt+1);
		if (s1>t1 || (s1&1)!=(t1&1))
			putchar('0');
		else
		{
			if (!s1 && t1)
			{
				if (s0==t0)
					putchar('0');
				else
					putchar('1');
			}
			else if (s0<t0 || s0 && t0 && s0%3!=t0%3)
				putchar('0');
			else
				putchar('1');
		}
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1E+5;
int s[N][2],pre[N][2],cnt[N][2],len[2],T,l,r,t,w;
void Init(){
	for(int i=0;i<=1;i++){
		char c=getchar();
		while ('A'<=c&&c<='C'){
			s[++len[i]][i]=c-'A';
			pre[len[i]][i]=pre[len[i]-1][i];
			if (c-'A'){
				pre[len[i]][i]++;
			}c=getchar();
		}scanf("\n");
	}for(int i=0;i<=1;i++){
		int last=0;
		for(int j=1;j<=len[i];j++){
			if (s[j][i])
				last=j;
			cnt[j][i]=j-last;
		}
	}
}
void Work(){
	scanf("%d",&T);
	while (T--){
		scanf("%d%d%d%d",&l,&r,&t,&w);
		int tmp1=pre[r][0]-pre[l-1][0];
		int tmp2=pre[w][1]-pre[t-1][1];
		if (tmp1>tmp2){
			printf("0");
			continue;
		}if (tmp1%2!=tmp2%2){
			printf("0");
			continue;
		}int cnt1=cnt[r][0];
		cnt1=min(cnt1,r-l+1);
		int cnt2=cnt[w][1];
		cnt2=min(cnt2,w-t+1);
		if (cnt1<cnt2){
			printf("0");
			continue;
		}if (tmp1==tmp2&&cnt1%3!=cnt2%3){
			printf("0");
			continue;
		}if (tmp1!=tmp2&&tmp1==0&&cnt1==cnt2){
			printf("0");
			continue;
		}
		printf("1");
	}
}
int main(){
	Init();
	Work();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1E+5;
int s[N][2],pre[N][2],cnt[N][2],len[2],T,l,r,t,w;
void Init(){
	for(int i=0;i<=1;i++){
		char c=getchar();
		while ('A'<=c&&c<='C'){
			s[++len[i]][i]=c-'A';
			pre[len[i]][i]=pre[len[i]-1][i];
			if (c-'A'){
				pre[len[i]][i]++;
			}c=getchar();
		}scanf("\n");
	}for(int i=0;i<=1;i++){
		int last=0;
		for(int j=1;j<=len[i];j++){
			if (s[j][i])
				last=j;
			cnt[j][i]=j-last;
			printf("%d ",cnt[j][i]);
		}printf("\n");
	}
}
void Work(){
	scanf("%d",&T);
	while (T--){
		scanf("%d%d%d%d",&l,&r,&t,&w);
		int tmp1=pre[r][0]-pre[l-1][0];
		int tmp2=pre[w][1]-pre[t-1][1];
		if (tmp1>tmp2){
			printf("0");
			continue;
		}if (tmp1%2!=tmp2%2){
			printf("0");
			continue;
		}int cnt1=cnt[r][0];
		cnt1=min(cnt1,r-l+1);
		int cnt2=cnt[w][1];
		cnt2=min(cnt2,w-t+1);
		if (cnt1<cnt2){
			printf("0");
			continue;
		}if (tmp1==tmp2&&cnt1%3!=cnt2%3){
			printf("0");
			continue;
		}if (tmp1!=tmp2&&tmp1==0&&cnt1==cnt2){
			printf("0");
			continue;
		}
		printf("1");
	}
}
int main(){
	Init();
	Work();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1E5+5;
int s[N][2],pre[N][2],cnt[N][2],len[2],T,l,r,t,w;
void Init(){
	for(int i=0;i<=1;i++){
		char c=getchar();
		while ('A'<=c&&c<='C'){
			s[++len[i]][i]=c-'A';
			pre[len[i]][i]=pre[len[i]-1][i];
			if (c-'A'){
				pre[len[i]][i]++;
			}c=getchar();
		}scanf("\n");
	}for(int i=0;i<=1;i++){
		int last=0;
		for(int j=1;j<=len[i];j++){
			if (s[j][i])
				last=j;
			cnt[j][i]=j-last;
		}
	}
}
void Work(){
	scanf("%d",&T);
	while (T--){
		scanf("%d%d%d%d",&l,&r,&t,&w);
		int tmp1=pre[r][0]-pre[l-1][0];
		int tmp2=pre[w][1]-pre[t-1][1];
		if (tmp1>tmp2){
			printf("0");
			continue;
		}if (tmp1%2!=tmp2%2){
			printf("0");
			continue;
		}int cnt1=cnt[r][0];
		cnt1=min(cnt1,r-l+1);
		int cnt2=cnt[w][1];
		cnt2=min(cnt2,w-t+1);
		if (cnt1<cnt2){
			printf("0");
			continue;
		}if (tmp1==tmp2&&cnt1%3!=cnt2%3){
			printf("0");
			continue;
		}if (tmp1!=tmp2&&tmp1==0&&cnt1==cnt2){
			printf("0");
			continue;
		}
		printf("1");
	}
}
int main(){
	Init();
	Work();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1E+5;
int s[N][2],pre[N][2],cnt[N][2],len[2],T,l,r,t,w;
void Init(){
	for(int i=0;i<=1;i++){
		char c=getchar();
		while ('A'<=c&&c<='C'){
			s[++len[i]][i]=c-'A';
			pre[len[i]][i]=pre[len[i]-1][i];
			if (c-'A'){
				pre[len[i]][i]++;
			}c=getchar();
		}scanf("\n");
	}for(int i=0;i<=1;i++){
		int last=0;
		for(int j=1;j<=len[i];j++){
			if (s[j][i])
				last=j;
			cnt[j][i]=j-last;
		}
	}
}
void Work(){
	scanf("%d",&T);
	while (T--){
		scanf("%d%d%d%d",&l,&r,&t,&w);
		int tmp1=pre[r][0]-pre[l-1][0];
		int tmp2=pre[w][1]-pre[t-1][1];
		if (tmp1>tmp2){
			printf("0");
			continue;
		}if (tmp1%2!=tmp2%2){
			printf("0");
			continue;
		}int cnt1=cnt[r][0];
		int cnt2=cnt[w][1];
		cnt1-=(tmp2-tmp1)/2;
		if (cnt1%3!=cnt2%3){
			printf("0");
			continue;
		}printf("1");
	}
}
int main(){
	Init();
	Work();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int s[N][3],s1[N][3],n,m;
int a[N],a1[N];
int main(){
//	freopen("Picking Strings.in","r",stdin);
//	freopen("Picking Strings.out","w",stdout);
	char c;
	for(c=getchar();c<'A'||c>'C';c=getchar());
	for(;c>='A'&&c<='C';c=getchar()){
		int x=c-'A';
		n++;
		memcpy(s[n],s[n-1],sizeof(s[n]));
		s[n][x]++;
		if(x==0)a[n]=a[n-1]+1;
	}
	for(c=getchar();c<'A'||c>'C';c=getchar());
	for(;c>='A'&&c<='C';c=getchar()){
		int x=c-'A';
		m++;
		memcpy(s1[m],s1[m-1],sizeof(s1[m]));
		s1[m][x]++;
		if(x==0)a1[n]=a[n-1]+1;
	}
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int l1,l2,r1,r2;
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		int x=s[r1][2]-s[l1-1][2]+s[r1][1]-s[l1-1][1];
		int y=s1[r2][2]-s1[l2-1][2]+s1[r2][1]-s1[l2-1][1];
		int ax=min(a[r1],r1-l1+1),ay=min(a1[r2],r2-l2+1);
		if(ax>ay)x+=2;
		if((x%2)==(y%2)&&y>=x&&ax>=ay)printf("1");else printf("0");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int s[N][3],s1[N][3],n,m;
int main(){
//	freopen("Picking Strings.in","r",stdin);
//	freopen("Picking Strings.out","w",stdout);
	char c;
	for(c=getchar();c<'A'||c>'C';c=getchar());
	for(;c>='A'&&c<='C';c=getchar()){
		int x=c-'A';
		n++;
		memcpy(s[n],s[n-1],sizeof(s[n]));
		s[n][x]++;
	}
	for(c=getchar();c<'A'||c>'C';c=getchar());
	for(;c>='A'&&c<='C';c=getchar()){
		int x=c-'A';
		m++;
		memcpy(s1[m],s1[m-1],sizeof(s1[m]));
		s1[m][x]++;
	}
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int l1,l2,r1,r2;
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		int x=s[r1][2]-s[l1-1][2]+s[r1][1]-s[l1-1][1];
		int y=s1[r2][2]-s1[l2-1][2]+s1[r2][1]-s1[l2-1][1];
		if((x%2)==(y%2)&&y>=x)printf("1");else printf("0");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int s[N][3],s1[N][3],n,m;
int main(){
//	freopen("Picking Strings.in","r",stdin);
//	freopen("Picking Strings.out","w",stdout);
	char c;
	for(c=getchar();c<'A'||c>'C';c=getchar());
	for(;c>='A'&&c<='C';c=getchar()){
		int x=c-'A';
		n++;
		memcpy(s[n],s[n-1],sizeof(s[n]));
		s[n][x]++;
	}
	for(c=getchar();c<'A'||c>'C';c=getchar());
	for(;c>='A'&&c<='C';c=getchar()){
		int x=c-'A';
		m++;
		memcpy(s1[m],s1[m-1],sizeof(s1[m]));
		s1[m][x]++;
	}
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int l1,l2,r1,r2;
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		int x=s[r1][2]-s[l1-1][2]+s[r1][1]-s[l1-1][1];
		int y=s1[r2][2]-s1[l2-1][2]+s1[r2][1]-s1[l2-1][1];
		if((x%2)==(y%2))printf("1");else printf("0");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int s[N][3],s1[N][3],n,m;
int a[N],a1[N];
int main(){
//	freopen("Picking Strings.in","r",stdin);
//	freopen("Picking Strings.out","w",stdout);
	char c;
	for(c=getchar();c<'A'||c>'C';c=getchar());
	for(;c>='A'&&c<='C';c=getchar()){
		int x=c-'A';
		n++;
		memcpy(s[n],s[n-1],sizeof(s[n]));
		s[n][x]++;
		if(x==0)a[n]=a[n-1]+1;
	}
	for(c=getchar();c<'A'||c>'C';c=getchar());
	for(;c>='A'&&c<='C';c=getchar()){
		int x=c-'A';
		m++;
		memcpy(s1[m],s1[m-1],sizeof(s1[m]));
		s1[m][x]++;
		if(x==0)a1[m]=a1[m-1]+1;
	}
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int l1,l2,r1,r2;
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		int x=s[r1][2]-s[l1-1][2]+s[r1][1]-s[l1-1][1];
		int y=s1[r2][2]-s1[l2-1][2]+s1[r2][1]-s1[l2-1][1];
		int ax=min(a[r1],r1-l1+1),ay=min(a1[r2],r2-l2+1);
		int c=ax-ay;
		if(x<=y){
			if(x%2==y%2){
				if(c>=0){
					if(x==y){
						if(c%3==0){
							printf("1");
							continue;
						}
					}else{
						if(x||c){
							printf("1");
							continue;
						}
					}
				}
			}
		}
		printf("0");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    stack<char> st;
    int q,a,b,c,d,i,aa,bb;
    char S[100009],T[100009];
    for(scanf("%s%s%d",S+1,T+1,&q); q--;)
    {
        for(scanf("%d%d%d%d",&a,&b,&c,&d),i=a,aa=0,bb=0; i<=b; ++i)
        {
            if(S[i]=='A') st.push('A');
            else
            {
                while(!st.empty()&&st.top()=='A') st.pop();
                st.push('B');
            }
        }
        while(!st.empty()&&st.top()=='A') --aa,st.pop();
        while(!st.empty()) --bb,st.pop();
        for(i=c; i<=d; ++i)
        {
            if(T[i]=='A') st.push('A');
            else
            {
                while(!st.empty()&&st.top()=='A') st.pop();
                st.push('B');
            }
        }
        while(!st.empty()&&st.top()=='A') ++aa,st.pop();
        while(!st.empty()) ++bb,st.pop();
        if(1&bb||bb<0) printf("0");
        else if(bb)
        {
            if(aa>0) printf("0");
            else printf("1");
        }
        else if(aa) printf("0");
        else printf("1");
    }
    exit(0);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 2000000
#include<cstring>
using namespace std;
char s[N],s1[N];
int t[N],t1[N];
int n,m,T;
int f[N*2],g[N*2];
void build(char*S,int*f,int*t,int l,int r,int s){
	if (l==r){
		f[s]=(S[l]=='B'||S[l]=='C');
		if (!f[s])t[s]=1;
		return;
	}
	build(S,f,t,l,(l+r)/2,s+s),build(S,f,t,(l+r)/2+1,r,s+s+1);
	f[s]=(f[s+s]+f[s+s+1]);
	if (t[s+s+1]==r-(l+r)/2)t[s]=t[s+s+1]+t[s+s];
	else
		t[s]=t[s+s+1];
}
int get(int*f,int*t,int l,int r,int s,int ll,int rr,int&v){
	if (r<ll||rr<l)return 0;
	if (ll<=l&&r<=rr){
		if (v==rr-r)v+=t[s];
		return f[s];
	}
	int s1=get(f,t,(l+r)/2+1,r,s+s+1,ll,rr,v);
	return s1+get(f,t,l,(l+r)/2,s+s,ll,rr,v);
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	scanf("%s",s1+1);
	m=strlen(s1+1);
	build(s,f,t,1,n,1);
	build(s1,g,t1,1,m,1);
	scanf("%d",&T);
	while (T--){
		int l,r,l1,r1;
		scanf("%d %d %d %d",&l,&r,&l1,&r1);
		int u1=0,u2=0;
		int v1=get(f,t,1,n,1,l,r,u1),v2=get(g,t1,1,m,1,l1,r1,u2);
		if (u2>u1){
			printf("0");
			continue;
		}
		if (!v1&&v2&&u1==u2){
			printf("0");
			continue;
		}
		u1=(u1-u2)%3+u2;
		if (u1-u2){
			v1+=2;
			u1=u2;
		}
		u1%=3,u2%=3;
		while (u1!=u2)(u1+=1)%=3,v1+=2;
		v1<=v2&&(v1&1)==(v2&1)?printf("1"):printf("0");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N=1e5+5;

string s,t;
int n,f[N],g[N];

int main() {
//	freopen("input.txt", "r", stdin);
	cin >> s >> t;
	for (int i = 0; i < s.size(); ++i) {
		f[i + 1] = f[i];
		if (s[i] != 'A') ++f[i+1];
	}
	for (int i = 0; i < t.size(); ++i) {
		g[i + 1] = g[i];
		if (t[i] != 'A') ++g[i+1];
	}
	scanf("%d", &n);
	string ret(n, '0');
	for (int i = 0; i < n; ++i) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x = f[b] - f[a-1];
		int y = g[d] - g[c-1];
		//cout << x <<' '<< y << endl;
		if ((x - y) % 2 == 0) ret[i] = '1';
	}
	cout << ret;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 100000 + 10;

char s[maxn],t[maxn];
int sb[maxn],sc[maxn],fa[maxn];
int sbt[maxn],sct[maxn],fat[maxn];
int n,m;
int Q;
int a,b,c,d;
int db,dc,dbt,dct;
int len1,len2;

void build()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1); m=strlen(s+2);
	for(int i=1;i<=n;i++)
	{
		fa[i]=i+1;
		sb[i]=sb[i-1]+(s[i]=='B'?1:0);
		sc[i]=sc[i-1]+(s[i]=='C'?1:0);
		if(s[i]=='A')
		{
			if(s[i-1]=='A') fa[i]=fa[i-1];
			else fa[i]=i;
		}
	}

	for(int i=1;i<=m;i++)
	{
		fat[i]=i+1;
		sbt[i]=sbt[i-1]+(t[i]=='B'?1:0);
		sct[i]=sct[i-1]+(t[i]=='C'?1:0);
		if(t[i]=='A')
		{
			if(t[i-1]=='A') fat[i]=fat[i-1];
			else fat[i]=i;
		}
	}
}

void solve()
{
	scanf("%d",&Q);
	while(Q--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		db=sb[b]-sb[a-1];
		dc=sc[b]-sc[a-1];
		dbt=sbt[d]-sbt[c-1];
		dct=sct[d]-sct[c-1];
		if(db+dc<dbt+dct) {
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);
			//printf("??? %d %d\n",db+dc,dbt+dct);
			if(len1<len2) printf("0");
			else if((dbt+dct-db-dc)%2==0) printf("1");
			else printf("0");
		}
		else if(db+dc>dbt+dct)
		{
			printf("0");
		}
		else
		{
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);
			//printf("??? %d %d\n",len1,len2);
			if(len1>=len2 && (len1-len2)%3==0) printf("1");
			else printf("0");
		}
	}
	printf("\n");
}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 100000 + 10;

char s[maxn],t[maxn];
int sb[maxn],sc[maxn],fa[maxn];
int sbt[maxn],sct[maxn],fat[maxn];
int n,m;
int Q;
int a,b,c,d;
int ds,dt;
int len1,len2;

void build()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1); m=strlen(t+1);
	for(int i=1;i<=n;i++)
	{
		fa[i]=i+1;
		sb[i]=sb[i-1]+(s[i]=='B'?1:0);
		sc[i]=sc[i-1]+(s[i]=='C'?1:0);
		if(s[i]=='A')
		{
			if(s[i-1]=='A') fa[i]=fa[i-1];
			else fa[i]=i;
		}
	}

	for(int i=1;i<=m;i++)
	{
		fat[i]=i+1;
		sbt[i]=sbt[i-1]+(t[i]=='B'?1:0);
		sct[i]=sct[i-1]+(t[i]=='C'?1:0);
		if(t[i]=='A')
		{
			if(t[i-1]=='A') fat[i]=fat[i-1];
			else fat[i]=i;
		}
	}
}

void solve()
{
	scanf("%d",&Q);
	while(Q--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ds=sb[b]-sb[a-1]+sc[b]-sc[a-1];
		dt=sbt[d]-sbt[c-1]+sct[d]-sct[c-1];

		if(ds<dt) {
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);

			if(len1<len2 || (len1-1<len2)&&(len1==b-a+1)) printf("0");
			else if((dt-ds)%2==0) printf("1");
			else printf("0");
		}
		else if(ds>dt)
		{
			printf("0");
		}
		else
		{
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);

			if(len1>=len2 && (len1-len2)%3==0) printf("1");
			else printf("0");
		}
	}
	printf("\n");
}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 100000 + 10;

char s[maxn],t[maxn];
int sb[maxn],sc[maxn],fa[maxn];
int sbt[maxn],sct[maxn],fat[maxn];
int n,m;
int Q;
int a,b,c,d;
int db,dc,dbt,dct;
int len1,len2;

void build()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1); m=strlen(t+1);
	for(int i=1;i<=n;i++)
	{
		fa[i]=i+1;
		sb[i]=sb[i-1]+(s[i]=='B'?1:0);
		sc[i]=sc[i-1]+(s[i]=='C'?1:0);
		if(s[i]=='A')
		{
			if(s[i-1]=='A') fa[i]=fa[i-1];
			else fa[i]=i;
		}
	}

	for(int i=1;i<=m;i++)
	{
		fat[i]=i+1;
		sbt[i]=sbt[i-1]+(t[i]=='B'?1:0);
		sct[i]=sct[i-1]+(t[i]=='C'?1:0);
		if(t[i]=='A')
		{
			if(t[i-1]=='A') fat[i]=fat[i-1];
			else fat[i]=i;
		}
	}
}

void solve()
{
	scanf("%d",&Q);
	while(Q--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		db=sb[b]-sb[a-1];
		dc=sc[b]-sc[a-1];
		dbt=sbt[d]-sbt[c-1];
		dct=sct[d]-sct[c-1];
		//printf("Test %d %d\n",db+dc,dbt+dct);
		if(db+dc<dbt+dct) {
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);
			//printf("??? %d %d\n",db+dc,dbt+dct);
			if(len1<len2) printf("0");
			else if((dbt+dct-db-dc)%2==0) printf("1");
			else printf("0");
		}
		else if(db+dc>dbt+dct)
		{
			printf("0");
		}
		else
		{
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);
			//printf("??? %d %d\n",len1,len2);
			if(len1>=len2 && (len1-len2)%3==0) printf("1");
			else printf("0");
		}
	}
	printf("\n");
}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 100000 + 10;

char s[maxn],t[maxn];
int sb[maxn],sc[maxn],fa[maxn];
int sbt[maxn],sct[maxn],fat[maxn];
int n,m;
int Q;
int a,b,c,d;
int db,dc,dbt,dct;
int len1,len2;

void build()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1); m=strlen(t+1);
	for(int i=1;i<=n;i++)
	{
		fa[i]=i+1;
		sb[i]=sb[i-1]+(s[i]=='B'?1:0);
		sc[i]=sc[i-1]+(s[i]=='C'?1:0);
		if(s[i]=='A')
		{
			if(s[i-1]=='A') fa[i]=fa[i-1];
			else fa[i]=i;
		}
	}

	for(int i=1;i<=m;i++)
	{
		fat[i]=i+1;
		sbt[i]=sbt[i-1]+(t[i]=='B'?1:0);
		sct[i]=sct[i-1]+(t[i]=='C'?1:0);
		if(t[i]=='A')
		{
			if(t[i-1]=='A') fat[i]=fat[i-1];
			else fat[i]=i;
		}
	}
}

void solve()
{
	scanf("%d",&Q);
	while(Q--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		db=sb[b]-sb[a-1];
		dc=sc[b]-sc[a-1];
		dbt=sbt[d]-sbt[c-1];
		dct=sct[d]-sct[c-1];
		//printf("Test %d %d\n",db+dc,dbt+dct);
		if(db+dc<dbt+dct) {
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);
			//printf("??? %d %d\n",db+dc,dbt+dct);
			if(len1-1<len2) printf("0");
			else if((dbt+dct-db-dc)%2==0) printf("1");
			else printf("0");
		}
		else if(db+dc>dbt+dct)
		{
			printf("0");
		}
		else
		{
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);
			//printf("??? %d %d\n",len1,len2);
			if(len1>=len2 && (len1-len2)%3==0) printf("1");
			else printf("0");
		}
	}
	printf("\n");
}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 100000 + 10;

char s[maxn],t[maxn];
int sb[maxn],sc[maxn],fa[maxn];
int sbt[maxn],sct[maxn],fat[maxn];
int n,m;
int Q;
int a,b,c,d;
int db,dc,dbt,dct;
int len1,len2;

void build()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1); m=strlen(t+1);
	for(int i=1;i<=n;i++)
	{
		fa[i]=i+1;
		sb[i]=sb[i-1]+(s[i]=='B'?1:0);
		sc[i]=sc[i-1]+(s[i]=='C'?1:0);
		if(s[i]=='A')
		{
			if(s[i-1]=='A') fa[i]=fa[i-1];
			else fa[i]=i;
		}
	}

	for(int i=1;i<=m;i++)
	{
		fat[i]=i+1;
		sbt[i]=sbt[i-1]+(t[i]=='B'?1:0);
		sct[i]=sct[i-1]+(t[i]=='C'?1:0);
		if(t[i]=='A')
		{
			if(t[i-1]=='A') fat[i]=fat[i-1];
			else fat[i]=i;
		}
	}
}

void solve()
{
	scanf("%d",&Q);
	while(Q--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		db=sb[b]-sb[a-1];
		dc=sc[b]-sc[a-1];
		dbt=sbt[d]-sbt[c-1];
		dct=sct[d]-sct[c-1];
		//printf("Test %d %d\n",db+dc,dbt+dct);
		if(db+dc<dbt+dct) {
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);
			//printf("??? %d %d\n",db+dc,dbt+dct);
			if(len1<len2 || (len1-1<len2)&&(len1==b-a+1)) printf("0");
			else if((dbt+dct-db-dc)%2==0) printf("1");
			else printf("0");
		}
		else if(db+dc>dbt+dct)
		{
			printf("0");
		}
		else
		{
			len1=b-fa[b]+1; len1=min(len1,b-a+1);
			len2=d-fat[d]+1; len2=min(len2,d-c+1);
			//printf("??? %d %d\n",len1,len2);
			if(len1>=len2 && (len1-len2)%3==0) printf("1");
			else printf("0");
		}
	}
	printf("\n");
}

int main()
{
	build();
	solve();

	return 0;
}


#include <cstdio>
#include <cstring>
#define min(a,b) ((a)<(b)?(a):(b))
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;

const int N=1e5+1;
int i,ns,nt,q,a,b,c,d,as[N],bs[N],at[N],bt[N],sa,sb,ta,tb,p;
char s[N],t[N];

int main()
{
	scanf("%s%s%d",s+1,t+1,&q);
	ns=strlen(s+1); nt=strlen(t+1);

	fo(i,1,ns)
		if(s[i]=='A')
				as[i]=as[i-1]+1,bs[i]=bs[i-1]  ;
		else	as[i]=0        ,bs[i]=bs[i-1]+1;
	fo(i,1,nt)
		if(t[i]=='A')
				at[i]=at[i-1]+1,bt[i]=bt[i-1]  ;
		else	at[i]=0        ,bt[i]=bt[i-1]+1;

	fo(i,1,q)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);

		sa=min(as[b],b-a+1); sb=bs[b]-bs[a-1];
		ta=min(at[d],d-c+1); tb=bt[d]-bt[c-1];

		if(sb>tb)    p=0;
		else
		if(sb==tb)   p=(sa>=ta&&(sa-ta)%3==0);
		else
		if(sb&&sb<tb)p=(sa>=ta&&(tb-sb)%2==0);
		else         p=(sa> ta&& tb    %2==0);
		printf("%d",p);
	}
}


#include <cstdio>
#include <cstring>
#define min(a,b) ((a)<(b)?(a):(b))
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;

const int N=1e5+1;
int i,ns,nt,q,a,b,c,d,as[N],bs[N],at[N],bt[N],sa,sb,ta,tb,p;
char s[N],t[N];

int main()
{
	scanf("%s%s%d",s+1,t+1,&q);
	ns=strlen(s+1); nt=strlen(t+1);

	fo(i,1,ns)
		if(s[i]=='A')
				as[i]=as[i-1]+1,bs[i]=bs[i-1]  ;
		else	as[i]=0        ,bs[i]=bs[i-1]+1;
	fo(i,1,nt)
		if(t[i]=='A')
				at[i]=at[i-1]+1,bt[i]=bt[i-1]  ;
		else	at[i]=0        ,bt[i]=bt[i-1]+1;

	fo(i,1,q)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);

		sa=min(as[b],b-a+1); sb=bs[b]-bs[a-1];
		ta=min(at[d],d-c+1); tb=bt[d]-bt[c-1];

		if(sb>tb)    p=0;
		else
		if(sb==tb)   p=(sa>=ta&&(sa-ta)%3==0);
		else
		if(sb&&sb<tb)p=(sa>=ta&&(tb-sb)&1==0);
		else         p=(sa> ta&& tb    &1==0);
		printf("%d",p);
	}
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int MaxLen = 100000;

int f[2][MaxLen + 1][2];
char s[2][MaxLen];
int q;

void Get(int x)
{
	int i,len=strlen(s[x]);
	for ( i = 1;i<=len;i++)
	{
		char c=s[x][i-1];
		f[x][i][0] = f[x][i - 1][0];
		f[x][i][1] = f[x][i - 1][1];

		if (c != 'A')
		{
			f[x][i][0]++;
			f[x][i][1] = 0;
		}
		else
			f[x][i][1]++;
	}
}

int main(int argc, char const *argv[])
{
	scanf("%s",s[0]);
	scanf("%s",s[1]);
	Get(0), Get(1);
	scanf("%d", &q);

	for (; q--;)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x = f[0][b][0] - f[0][a - 1][0], y = f[1][d][0] - f[1][c - 1][0], z = min(f[0][b][1], b - a + 1) - min(f[1][d][1], d - c + 1);

		if (x <= y)
			if ((x % 2) == (y % 2))
				if (z >= 0)
					if (x == y)
					{
						if ((z % 3) == 0)
						{
							printf("1");
							continue;
						}
					}
					else if (x || z)
					{
						printf("1");
						continue;
					}

		printf("0");
	}

	printf("\n");
	return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]= jj0[i-1]+1;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i] = jj1[i-1]+1;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c2-c1)%2)
				cout<<0;
			else if(jj0[r1]<jj1[r2]||(jj1[r2]&&((jj0[r1]-jj1[r2])%3-(c2-c1)/2)>0)||((!jj1[r2])&&(jj0[r1]%3)&&c1==c2))
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 100005
char s[N],t[N];
int pre[N][2],p2[N][2];

int main()
{
	cin>>s+1>>t+1;
	for(int i = 1;i<=strlen(s+1);i++){
		if(s[i]>'A')
		pre[i][s[i]-'A'-1]++;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;i<=strlen(t+1);i++){
		if(t[i]>'A')
		p2[i][t[i]-'A'-1]++;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
			}
			else if((c1-c2)%2)
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 100005
char s[N],t[N];
int pre[N][2],p2[N][2];

int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;i<=strlen(s+1);i++){
		if(s[i]>'A')
		pre[i][s[i]-'A'-1]++;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;i<=strlen(t+1);i++){
		if(t[i]>'A')
		p2[i][t[i]-'A'-1]++;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c1-c2)%2)
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]++;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i]++;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c2-c1)%2)
				cout<<0;
			else if(jj0[r1]<jj1[r2]||(jj1[r2]&&((jj0[r1]-jj1[r2])%3-(c2-c1)/2)>0)||((!jj1[r2])&&(jj0[r1]%3)&&c1==c2))
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]++;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i]++;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c2-c1)%2)
				cout<<0;
			else if(jj0[r1]<jj1[r2]||(jj1[r2]&&((jj0[r1]-jj1[r2])%3-(c2-c1)/2)>0))
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]= jj0[i-1]+1;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i] = jj1[i-1]+1;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 = pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else if(c1==c2&&c1==0){
			int len1 = r1-l1+1;
			int len2 = r2-l2+1;
			if(len1<len2||(len1-len2)%3)
				cout<<0;
			else
				cout<<1;
		}
		else if((c2-c1)%2)
			cout<<0;
		else if(jj0[r1]<jj1[r2]||(((jj0[r1]-jj1[r2])%3)&&(c1==c2) )||( (c1==0) &&( (jj0[r1]-jj0[l1-1])<=jj1[r2]) ))
			cout<<0;
		else
			cout<<1;
	}
	cout<<endl;
	return 0;
}

/*#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<fstream>
#include<functional>
#include<list>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
typedef unsigned long long ull;
const int N = 100000 + 5;
#define ll long long
ll dp[2005][2005];//len now
#define mod 1000000007

int main(){
ios::sync_with_stdio(false);
ull n;
int q;
ull a[65],sum[65];
a[1] = sum[1] = 1;
for(int i = 2;i<=63;i++){
a[i] = a[i-1]*2;
sum[i] = sum[i-1]+a[i];
}
while(cin>>n){
ull tmp = n-1;
int idx = 1;
while(tmp<sum[idx]) idx++;
cin>>q;
for(int i = 0;i<q;i++){
ull pos;
cin>>pos;
if(pos%2)
cout<<(pos+1)/2<<endl;
else{

}
}
}
}
*/


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]= jj0[i-1]+1;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i] = jj1[i-1]+1;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 = pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c2-c1)%2)
				cout<<0;
			else if(jj0[r1]<jj1[r2]||(((jj0[r1]-jj1[r2])%3)&&c1==c2)||(c1==0&&jj0[r1]==jj1[r2]))
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}
/*#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<fstream>
#include<functional>
#include<list>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
typedef unsigned long long ull;
const int N = 100000 + 5;
#define ll long long
ll dp[2005][2005];//len now
#define mod 1000000007

int main(){
ios::sync_with_stdio(false);
ull n;
int q;
ull a[65],sum[65];
a[1] = sum[1] = 1;
for(int i = 2;i<=63;i++){
a[i] = a[i-1]*2;
sum[i] = sum[i-1]+a[i];
}
while(cin>>n){
ull tmp = n-1;
int idx = 1;
while(tmp<sum[idx]) idx++;
cin>>q;
for(int i = 0;i<q;i++){
ull pos;
cin>>pos;
if(pos%2)
cout<<(pos+1)/2<<endl;
else{

}
}
}
}
*/


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]= jj0[i-1]+1;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i] = jj1[i-1]+1;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c2-c1)%2)
				cout<<0;
			else if(jj0[r1]<jj1[r2]||(((jj0[r1]-jj1[r2])%3)&&c1==c2))
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 100005
char s[N],t[N];
int pre[N][2],p2[N][2];

int main()
{
	cin>>s+1>>t+1;
	for(int i = 1;i<strlen(s+1);i++){
		if(s[i]>'A')
		pre[i][s[i]-'A'-1]++;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;i<strlen(t+1);i++){
		if(t[i]>'A')
		p2[i][t[i]-'A'-1]++;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r1][0]-p2[l1-1][0]+p2[r1][1]-p2[l1-1][1];
		if(c1==c2&&c2==0){
			int len1 = r1-l1+1,len2 = r2-l2+1;
			if(len1<len2)
				swap(len1,len2);
			if((len1-len2)%3)
				cout<<0;
			else
				cout<<1;
		}
		else{
			if(c1<c2)
				swap(c1,c2);
			if((c1-c2)%2)
				cout<<0;
			else
				cout<<1;
		}
	}
	cout<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 100005
char s[N],t[N];
int pre[N][2],p2[N][2];

int main()
{
	cin>>s+1>>t+1;
	for(int i = 1;i<=strlen(s+1);i++){
		if(s[i]>'A')
		pre[i][s[i]-'A'-1]++;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;i<=strlen(t+1);i++){
		if(t[i]>'A')
		p2[i][t[i]-'A'-1]++;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c1-c2)%2)
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];

int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A')
			pre[i][s[i]-'A'-1]++;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A')
			p2[i][t[i]-'A'-1]++;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 =c1+pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c1-c2)%2)
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]= jj0[i-1]+1;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i] = jj1[i-1]+1;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 = pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c2-c1)%2)
				cout<<0;
			else if(jj0[r1]<jj1[r2]||(((jj0[r1]-jj1[r2])%3)&&(c1==c2) )||( (c1==0) &&( (jj0[r1]-jj0[l1-1])==jj1[r2]) ))
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}

/*#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<fstream>
#include<functional>
#include<list>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
typedef unsigned long long ull;
const int N = 100000 + 5;
#define ll long long
ll dp[2005][2005];//len now
#define mod 1000000007

int main(){
ios::sync_with_stdio(false);
ull n;
int q;
ull a[65],sum[65];
a[1] = sum[1] = 1;
for(int i = 2;i<=63;i++){
a[i] = a[i-1]*2;
sum[i] = sum[i-1]+a[i];
}
while(cin>>n){
ull tmp = n-1;
int idx = 1;
while(tmp<sum[idx]) idx++;
cin>>q;
for(int i = 0;i<q;i++){
ull pos;
cin>>pos;
if(pos%2)
cout<<(pos+1)/2<<endl;
else{

}
}
}
}
*/


#include<iostream>
#include<cstring>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<string>
#include<list>
using namespace std;
#define eps 1e-9
#define inf 0x3fffffff
#define N 300006
#define mode 100000000
#define ull unsigned long long
#define ll long long
#define ct(w,a) make_pair<int,int>(w,a)
#define pii pair<int,int>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define N 1000005
char s[N],t[N];
int pre[N][2],p2[N][2];
int jj0[N],jj1[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s+1>>t+1;
	for(int i = 1;s[i];i++){
		if(s[i]>'A'){
			pre[i][s[i]-'A'-1]++;
			jj0[i] = 0;
		}
		else
			jj0[i]= jj0[i-1]+1;
		pre[i][0]+=pre[i-1][0];
		pre[i][1]+=pre[i-1][1];
	}
	for(int i = 1;t[i];i++){
		if(t[i]>'A'){
			p2[i][t[i]-'A'-1]++;
			jj1[i] = 0;
		}
		else
			jj1[i] = jj1[i-1]+1;
		p2[i][0]+=p2[i-1][0];
		p2[i][1]+=p2[i-1][1];
	}
	int n ;
	cin>>n;
	for(int i = 0;i<n;i++){
		int l1,l2,r1,r2;
		cin>>l1>>r1>>l2>>r2;
		int c1 = 0,c2 = 0;
		c1 = pre[r1][0]-pre[l1-1][0]+pre[r1][1]-pre[l1-1][1];
		c2 = p2[r2][0]-p2[l2-1][0]+p2[r2][1]-p2[l2-1][1];
		if(c1>c2){
			cout<<0;
		}
		else{
			if(c1==c2&&c1==0){
				int len1 = r1-l1+1;
				int len2 = r2-l2+1;
				if(len1<len2||(len1-len2)%3)
					cout<<0;
				else
					cout<<1;
			}
			else if((c2-c1)%2)
				cout<<0;
			else if(jj0[r1]<jj1[r2]||(((jj0[r1]-jj1[r2])%3)&&c1==c2)||(c1==0&&(jj0[r1]-jj0[l1-1])==jj1[r2]))
				cout<<0;
			else
				cout<<1;
		}

	}
	cout<<endl;
	return 0;
}

/*#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<fstream>
#include<functional>
#include<list>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
typedef unsigned long long ull;
const int N = 100000 + 5;
#define ll long long
ll dp[2005][2005];//len now
#define mod 1000000007

int main(){
ios::sync_with_stdio(false);
ull n;
int q;
ull a[65],sum[65];
a[1] = sum[1] = 1;
for(int i = 2;i<=63;i++){
a[i] = a[i-1]*2;
sum[i] = sum[i-1]+a[i];
}
while(cin>>n){
ull tmp = n-1;
int idx = 1;
while(tmp<sum[idx]) idx++;
cin>>q;
for(int i = 0;i<q;i++){
ull pos;
cin>>pos;
if(pos%2)
cout<<(pos+1)/2<<endl;
else{

}
}
}
}
*/


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=100010;

char ss[N],st[N];
int s[N],t[N],cs[N],ct[N],lcs[N],lct[N];
int main() {
	scanf("%s",ss+1); scanf("%s",st+1);
	int n=strlen(ss+1),m=strlen(st+1);
	for (int i=1;i<=n;++i) s[i]=!(ss[i]=='A'),cs[i]=cs[i-1]+s[i];
	for (int i=1;i<=m;++i) t[i]=!(st[i]=='A'),ct[i]=ct[i-1]+t[i];
	for (int i=1;i<=n;++i) if (s[i]) lcs[i]=0; else lcs[i]=lcs[i-1]+1;
	for (int i=1;i<=m;++i) if (t[i]) lct[i]=0; else lct[i]=lct[i-1]+1;
	int Q; scanf("%d",&Q);
	while (Q--) {
		int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
		int cys=cs[b]-cs[a-1],cyt=ct[d]-ct[c-1];
		if (cys==0) {
			if (cyt==0) printf("%d",b-a>=d-c && (b-a)%3 == (d-c)%3);
			else if (cyt&1) printf("0");
			else printf("%d",b-a+1>lct[d]);
		} else {
			if (lcs[b]<lct[d]) printf("0");
			else if (lcs[b]==lct[d]) {
				if (cyt<cys || ((cyt-cys)&1)) printf("0");
				else printf("1");
			} else {
				if (lcs[b]%3 != lct[d]%3) cys+=2;
				if (cyt<cys || ((cyt-cys)&1)) printf("0");
				else printf("1");
			}
		}
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=100010;

char ss[N],st[N];
int s[N],t[N],cs[N],ct[N],lcs[N],lct[N];
int main() {
	scanf("%s",ss+1); scanf("%s",st+1);
	int n=strlen(ss+1),m=strlen(st+1);
	for (int i=1;i<=n;++i) s[i]=!(ss[i]=='A'),cs[i]=cs[i-1]+s[i];
	for (int i=1;i<=m;++i) t[i]=!(st[i]=='A'),ct[i]=ct[i-1]+t[i];
	for (int i=1;i<=n;++i) if (s[i]) lcs[i]=0; else lcs[i]=lcs[i-1]+1;
	for (int i=1;i<=m;++i) if (t[i]) lct[i]=0; else lct[i]=lct[i-1]+1;
	int Q; scanf("%d",&Q);
	while (Q--) {
		int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
		int cys=cs[b]-cs[a-1],cyt=ct[d]-ct[c-1];
		if (cys==0) {
			if (cyt==0) printf("%d",b-a>=d-c && (b-a)%3 == (d-c)%3);
			else if (cyt&1) printf("0");
			else printf("%d",b-a+1>lct[d]);
		} else {
			if (lcs[b]<lct[d]) printf("0");
			else if (lcs[b]==lct[d]) {
				if (cyt<cys || ((cyt-cys)&1)) printf("0");
				else printf("1");
			} else {
				cys+=2;
				if (cyt<cys || ((cyt-cys)&1)) printf("0");
				else printf("1");
			}
		}
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=100010;

char ss[N],st[N];
int s[N],t[N],cs[N],ct[N],lcs[N],lct[N];
int main() {
	scanf("%s",ss+1); scanf("%s",st+1);
	int n=strlen(ss+1),m=strlen(st+1);
	for (int i=1;i<=n;++i) s[i]=!(ss[i]=='A'),cs[i]=cs[i-1]+s[i];
	for (int i=1;i<=m;++i) t[i]=!(st[i]=='A'),ct[i]=ct[i-1]+t[i];
	for (int i=1;i<=n;++i) if (s[i]) lcs[i]=0; else lcs[i]=lcs[i-1]+1;
	for (int i=1;i<=m;++i) if (t[i]) lct[i]=0; else lct[i]=lct[i-1]+1;
	int Q; scanf("%d",&Q);
	while (Q--) {
		int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
		int cys=cs[b]-cs[a-1],cyt=ct[d]-ct[c-1];
		if (cys==0) {
			if (cyt==0) printf("%d",b-a>d-c && (b-a)%3 == (d-c)%3);
			else if (cyt&1) printf("0");
			else printf("%d",b-a+1>lct[d]);
		} else {
			if (lcs[b]<lct[d]) printf("0");
			else if (lcs[b]==lct[d]) {
				if (cyt<cys || ((cyt-cys)&1)) printf("0");
				else printf("1");
			} else {
				cys+=2;
				if (cyt<cys || ((cyt-cys)&1)) printf("0");
				else printf("1");
			}
		}
	}
}


#include <cstring>
#include <cstdio>

struct A{
	int a[100005],b[100005],len;
	char st[100005];
	void Len(){len=strlen(st+1);}
}s,t;

inline int min(int x,int y){return x<y?x:y;}

int a,b,c,d;

bool solve(){
	int p=min(s.a[b],b-a)%3,q=min(t.a[d],d-c)%3;
	int x=s.b[b]-s.b[a],y=t.b[d]-t.b[c];
	if (x>y) return 1;else if (x==y){
		return p!=q;
	}else{
		if ((y-x)&1) return 1;
		return p<q;
	}
}

int main(){
	scanf("%s\n%s",s.st+1,t.st+1);
	s.Len();
	for (int i=1;i<=s.len;i++){
		s.a[i]=s.st[i]=='A'?s.a[i-1]+1:0;
		s.b[i]=s.b[i-1]+(s.st[i]!='A');
	}
	t.Len();
	for (int i=1;i<=t.len;i++){
		t.a[i]=t.st[i]=='A'?t.a[i-1]+1:0;
		t.b[i]=t.b[i-1]+(t.st[i]!='A');
	}
	int Q;
	for (scanf("%d",&Q);Q--;){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a--,c--;
		if (solve()) putchar(48);else putchar(49);
	}
}


#include <cstring>
#include <cstdio>

struct A{
	int a[100005],b[100005],len;
	char st[100005];
	void Len(){len=strlen(st+1);}
}s,t;

inline int min(int x,int y){return x<y?x:y;}

int a,b,c,d;

bool solve(){
	int p=min(s.a[b],b-a),q=min(t.a[d],d-c);
	int x=s.b[b]-s.b[a],y=t.b[d]-t.b[c];
	if (p<q||(x==0&&y&&p==q)) return 1;
	p%=3,q%=3;
	if (x>y) return 1;else if (x==y){
		return p!=q;
	}else return (y-x)&1;
}

int main(){
	scanf("%s\n%s",s.st+1,t.st+1);
	s.Len();
	for (int i=1;i<=s.len;i++){
		s.a[i]=s.st[i]=='A'?s.a[i-1]+1:0;
		s.b[i]=s.b[i-1]+(s.st[i]!='A');
	}
	t.Len();
	for (int i=1;i<=t.len;i++){
		t.a[i]=t.st[i]=='A'?t.a[i-1]+1:0;
		t.b[i]=t.b[i-1]+(t.st[i]!='A');
	}
	int Q;
	for (scanf("%d",&Q);Q--;){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a--,c--;
		if (solve()) putchar(48);else putchar(49);
	}
}


#include <cstring>
#include <cstdio>

struct A{
	int a[100005],b[100005],len;
	char st[100005];
	void Len(){len=strlen(st+1);}
}s,t;

inline int min(int x,int y){return x<y?x:y;}

int a,b,c,d;

bool solve(){
	int p=min(s.a[b],b-a),q=min(t.a[d],d-c);
	int x=s.b[b]-s.b[a],y=t.b[d]-t.b[c];
	if (q>p) return 1;
	p%=3,q%=3;
	if (x>y) return 1;else if (x==y){
		return p!=q;
	}else return (y-x)&1;
}

int main(){
	scanf("%s\n%s",s.st+1,t.st+1);
	s.Len();
	for (int i=1;i<=s.len;i++){
		s.a[i]=s.st[i]=='A'?s.a[i-1]+1:0;
		s.b[i]=s.b[i-1]+(s.st[i]!='A');
	}
	t.Len();
	for (int i=1;i<=t.len;i++){
		t.a[i]=t.st[i]=='A'?t.a[i-1]+1:0;
		t.b[i]=t.b[i-1]+(t.st[i]!='A');
	}
	int Q;
	for (scanf("%d",&Q);Q--;){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a--,c--;
		if (solve()) putchar(48);else putchar(49);
	}
}


#include <cstring>
#include <cstdio>

inline int readin(){
	int x=0,c;
	for (;(c=getchar())<'0'||c>'9';);
	for (;c>='0'&&c<='9';) x=(x<<1)+(x<<3)+c-48,c=getchar();
	return x;
}

struct E{int nex,to;}e[10005];
int head[105],num,dis[105],vis[105];

int add_E(int u,int v){
	e[++num]=(E){head[u],v},head[u]=num;
	e[++num]=(E){head[v],u},head[v]=num;
}

int t[105][105],r[105][105],f[105],q[2333],tot;

void dfs(int u){
	r[tot][dis[u]]=u;
	t[tot][dis[u]]++;
	f[u]=1;
	for (int i=head[u],v;i;i=e[i].nex) if (i&1) if (!f[v=e[i].to]) if (dis[v]<dis[u]) dfs(v);
}

void solve(int T,int S){
	++tot;
	memset(dis,0x7f,sizeof dis);
	int l=0,r=0;
	vis[q[++r]=S]=1;
	dis[S]=1;
	while (l<r){
		int u=q[++l];
		vis[u]=0;
		for (int i=head[u],v;i;i=e[i].nex) if (!(i&1))
		if (dis[u]+1<dis[v=e[i].to]){
			dis[v]=dis[u]+1;
			if (!vis[v]) vis[v]=1,q[++r]=v;
		}
	}
	if (dis[T]<233) dfs(T);
	memset(vis,0,sizeof vis);
	memset(f,0,sizeof f);
}

int main(){
	memset(t,0xff,sizeof t);
	int n=readin(),m=readin(),S=readin(),T=readin();
	for (;m--;) add_E(readin(),readin());
	for (m=readin();m--;) solve(readin(),readin());
	num=0;
	memset(e,0,sizeof e);
	memset(head,0,sizeof head);
	for (int i=1;i<=tot;i++)
		for (int j=1;j<n;j++) if (!t[i][j])
			for (int k=j;++k<=n;) if (!t[i][k]) e[++num]=(E){head[r[i][j]],r[i][k]},head[r[i][j]]=num;
	int l=0,r=0;
	memset(dis,0x7f,sizeof dis);
	q[++r]=S;
	dis[S]=0;
	while (l<r){
		int u=q[++l];
		vis[u]=0;
		for (int i=head[u],v;i;i=e[i].nex) if (dis[u]+1<dis[v=e[i].to]){
			dis[v]=dis[u]+1;
			if (!vis[v]) vis[v]=1,q[++r]=v;
		}
	}
	if (dis[T]==0x7f7f7f7f) puts("-1");else printf("%d",dis[T]);
}


#include <cstring>
#include <cstdio>

struct A{
	int a[100005],b[100005],len;
	char st[100005];
	void Len(){len=strlen(st+1);}
}s,t;

inline int min(int x,int y){return x<y?x:y;}

int a,b,c,d;

bool solve(){
	int p=min(s.a[b],b-a),q=min(t.a[d],d-c);
	int x=s.b[b]-s.b[a],y=t.b[d]-t.b[c];
	if (p<q||(x==0&&p==q)) return 1;
	p%=3,q%=3;
	if (x>y) return 1;else if (x==y){
		return p!=q;
	}else return (y-x)&1;
}

int main(){
	scanf("%s\n%s",s.st+1,t.st+1);
	s.Len();
	for (int i=1;i<=s.len;i++){
		s.a[i]=s.st[i]=='A'?s.a[i-1]+1:0;
		s.b[i]=s.b[i-1]+(s.st[i]!='A');
	}
	t.Len();
	for (int i=1;i<=t.len;i++){
		t.a[i]=t.st[i]=='A'?t.a[i-1]+1:0;
		t.b[i]=t.b[i-1]+(t.st[i]!='A');
	}
	int Q;
	for (scanf("%d",&Q);Q--;){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a--,c--;
		if (solve()) putchar(48);else putchar(49);
	}
}


#include <cstring>
#include <cstdio>

struct A{
	int a[100005],b[100005],len;
	char st[100005];
	void Len(){len=strlen(st+1);}
}s,t;

inline int min(int x,int y){return x<y?x:y;}

int a,b,c,d;

bool solve(){
	int p=min(s.a[b],b-a)%3,q=min(t.a[d],d-c)%3;
	int x=s.b[b]-s.b[a],y=t.b[d]-t.b[c];
	if (x>y) return 1;else if (x==y){
		return p!=q;
	}else{
		if ((y-x)&1) return 1;
		return p<q;
	}
}

int main(){
	freopen("233.out","w",stdout);
	scanf("%s\n%s",s.st+1,t.st+1);
	s.Len();
	for (int i=1;i<=s.len;i++){
		s.a[i]=s.st[i]=='A'?s.a[i-1]+1:0;
		s.b[i]=s.b[i-1]+(s.st[i]!='A');
	}
	t.Len();
	for (int i=1;i<=t.len;i++){
		t.a[i]=t.st[i]=='A'?t.a[i-1]+1:0;
		t.b[i]=t.b[i-1]+(t.st[i]!='A');
	}
	int Q;
	for (scanf("%d",&Q);Q--;){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a--,c--;
		if (solve()) putchar(48);else putchar(49);
	}
}


#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    string s,t;
    //freopen("test.inp","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    int q;
    cin>>s>>t;
    scanf("%d",&q);
    for (int i=1;i<=q;++i){
        int x,y,u,v,r=0,w=0,j1,j2;
        scanf("%d%d%d%d",&x,&y,&u,&v);
        for (j1=v-1;j1>=u-1;--j1)
            if (t[j1]!='A') break; else w++;
        for (j2=y-1;j2>=x-1;--j2)
            if (s[j2]!='A') break; else r++;
        if (r%3==w%3&&r>=w){
            r=0;w=0;
            for (int j=x-1;j<=j2;++j)
                if (s[j]=='A') r+=2; else r++;
            for (int j=u-1;j<=j1;++j)
                if (t[j]=='A') w+=2; else w++;
            if (r%2==w%2) printf("1"); else printf("0");
        }else printf("0");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    string s,t;
    int q;
    cin>>s>>t;
    scanf("%d",&q);
    for (int i=1;i<=q;++i){
        int x,y,u,v,r=0,w=0,j1,j2;
        scanf("%d%d%d%d",&x,&y,&u,&v);
        for (j1=v-1;j1>=u-1;--j1)
            if (t[j1]!='A') break; else w++;
        for (j2=y-1;j2>=x-1;--j2)
            if (s[j2]!='A') break; else r++;
        if (r%3==w%3&&r>=w){
            r=0;w=0;
            for (int j=x-1;j<=j2;++j)
                if (s[j]=='A') r+=2; else r++;
            for (int j=u-1;j<=j1;++j)
                if (t[j]=='A') w+=2; else w++;
            if (r%2==w%2) printf("1"); else printf("0");
        }else printf("0");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    string s,t;
    //freopen("test.inp","r",stdin);
    int q;
    cin>>s>>t;
    scanf("%d",&q);
    for (int i=1;i<=q;++i){
        int x,y,u,v,r=0,w=0,j1,j2;
        scanf("%d%d%d%d",&x,&y,&u,&v);
        for (j1=v-1;j1>=u-1;--j1)
            if (t[j1]!='A') break; else w++;
        for (j2=y-1;j2>=x-1;--j2)
            if (s[j2]!='A') break; else r++;
        if (r%3==w%3&&r>=w){
            r=0;w=0;
            for (int j=x-1;j<=j2;++j)
                if (s[j]=='A') r+=2; else r++;
            for (int j=u-1;j<=j1;++j)
                if (t[j]=='A') w+=2; else w++;
            if (r%2==w%2) printf("1"); else printf("0");
        }else printf("0");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    string s,t;
    //freopen("test.inp","r",stdin);
    int q;
    cin>>s>>t;
    scanf("%d",&q);
    for (int i=1;i<=q;++i){
        int x,y,u,v,r=0,w=0;
        scanf("%d%d%d%d",&x,&y,&u,&v);
        for (int j=x-1;j<y;++j)
            if (s[j]=='A') r+=2; else r++;
        for (int j=u-1;j<v;++j)
            if (t[j]=='A') w+=2; else w++;
        if (r%2==w%2) printf("1");
        else printf("0");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>

#define I register int
#define Get getchar()
#define F(i, a, b) for (I i = a; i <= b; i ++)
#define N 100010

using namespace std;

int a, b, c, d, cnt, lens, lent, LENS, LENT, Lena, Lenb, Sb, Tb, las, Q;
int preS[N], preT[N], Gos[N], Got[N], SumS[N], SumT[N];
char S[N], T[N];

void R(I &x) {
	char c = Get; x = 0; I t = 1;
	for (; !isdigit(c); c = Get) t = (c == '-' ? - 1 : t);
	for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = Get); x *= t;
}

bool Good() {
	if (++ cnt == 38)
		cnt = cnt;
	Lena = min(b - Gos[b], LENS), Lenb = min(d - Got[d], LENT);
	if (Lena >= Lenb) {
		Sb = SumS[b - Lena] - SumS[a - 1];
		Tb = SumT[d - Lenb] - SumT[c - 1];
		if (Lena > Lenb && (Lena - Lenb) % 3 > 0 && Sb + 2 > Tb) return false;
		if (Lena == Lenb && Lena == LENS && Lenb < LENT) return false;
		if (Sb <= Tb && ((Tb - Sb) % 2 == 0)) return true;
	}
	return false;
}

int main() {
	scanf("%s%s", S + 1, T + 1), lens = strlen(S + 1), lent = strlen(T + 1);
	F(i, 1, lens) S[i] = (S[i] == 'C' ? 'B' : S[i]);
	F(i, 1, lent) T[i] = (T[i] == 'C' ? 'B' : T[i]);
	F(i, 1, lens) if (S[i] == 'B') preS[las] = i, las = i, SumS[i] = SumS[i - 1] + 1, Gos[i] = i; else Gos[i] = las, SumS[i] = SumS[i - 1]; las = 0;
	F(i, 1, lent) if (T[i] == 'B') preT[las] = i, las = i, SumT[i] = SumT[i - 1] + 1, Got[i] = i; else Got[i] = las, SumT[i] = SumT[i - 1];
	for (R(Q); Q --; ) {
		R(a), R(b), R(c), R(d), LENS = b - a + 1, LENT = d - c + 1;
		if (Good()) putchar('1'); else putchar('0');
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>

#define I register int
#define Get getchar()
#define F(i, a, b) for (I i = a; i <= b; i ++)
#define N 100010

using namespace std;

int a, b, c, d, lens, lent, LENS, LENT, Lena, Lenb, Sb, Tb, las, Q;
int preS[N], preT[N], Gos[N], Got[N], SumS[N], SumT[N];
char S[N], T[N];

void R(I &x) {
	char c = Get; x = 0; I t = 1;
	for (; !isdigit(c); c = Get) t = (c == '-' ? - 1 : t);
	for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = Get); x *= t;
}

bool Good() {
	Lena = min(b - Gos[b], LENS), Lenb = min(d - Got[d], LENT);
	if (Lena >= Lenb) {
		Sb = SumS[b - Lena] - SumS[a - 1];
		Tb = SumT[d - Lenb] - SumT[c - 1];
		if (Lena > Lenb && (Lena - Lenb) % 3 > 0 && Sb + 2 > Tb) return false;
		if (Sb <= Tb && ((Tb - Sb) % 2 == 0)) return true;
	}
	return false;
}

int main() {
	scanf("%s%s", S + 1, T + 1), lens = strlen(S + 1), lent = strlen(T + 1);
	F(i, 1, lens) S[i] = (S[i] == 'C' ? 'B' : S[i]);
	F(i, 1, lent) T[i] = (T[i] == 'C' ? 'B' : T[i]);
	F(i, 1, lens) if (S[i] == 'B') preS[las] = i, las = i, SumS[i] = SumS[i - 1] + 1, Gos[i] = i; else Gos[i] = las, SumS[i] = SumS[i - 1]; las = 0;
	F(i, 1, lent) if (T[i] == 'B') preT[las] = i, las = i, SumT[i] = SumT[i - 1] + 1, Got[i] = i; else Got[i] = las, SumT[i] = SumT[i - 1];
	for (R(Q); Q --; ) {
		R(a), R(b), R(c), R(d), LENS = b - a + 1, LENT = d - c + 1;
		if (Good()) putchar('1'); else putchar('0');
	}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10,mod = 1e9 + 7;
char s[maxn],t[maxn];
int bita[maxn],bitb[maxn],ans[maxn],pa[maxn],pb[maxn];

int lowbit(int x) {
    return x&-x;
}

void update(int b[],int v,int val,int up){
    while(v <= up){
        b[v] += val;
        v += lowbit(v);
    }
}

int sum(int b[],int v){
    int res = 0;
    while(v){
        res += b[v];
        v -= lowbit(v);
    }
    return res;
}

void init(){
    int n = strlen(s+1);
    int m = strlen(t+1);

    for(int i = 1;i <= n;i++){
        update(bita,i,s[i]!='A',n);
        if(s[i] == 'A') pa[i] = pa[i-1]+1;
        else pa[i] = 0;
    }
    for(int i = 1;i <= m;i++){
        update(bitb,i,t[i]!='A',m);
        if(t[i] == 'A') pb[i] = pb[i-1]+1;
        else pb[i] = 0;
    }
}

int main(){
    scanf("%s%s",s+1,t+1);
    init();

    int T;
    scanf("%d",&T);
    int cnt = 0;
    while(T--){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int p = sum(bita,b) - sum(bita,a-1);
        int q = sum(bitb,d) - sum(bitb,c-1);
        if(p < q){
            if((q-p)&1) ans[cnt] = 0;
            else ans[cnt] = 1;
        }
        else if(p > q) ans[cnt] = 0;
        else {
            int k1 = min(pa[b],b-a+1);
            int k2 = min(pb[d],d-c+1);
            if((k1 - k2)%3==0) ans[cnt] = 1;
            else ans[cnt] = 0;
        }
        cnt++;
    }
    for(int i = 0;i < cnt;i++) printf("%d",ans[i]);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10,mod = 1e9 + 7;
char s[maxn],t[maxn];
int bita[maxn],bitb[maxn],ans[maxn],pa[maxn],pb[maxn];

int lowbit(int x) {
    return x&-x;
}

void update(int b[],int v,int val,int up){
    while(v <= up){
        b[v] += val;
        v += lowbit(v);
    }
}

int sum(int b[],int v){
    int res = 0;
    while(v){
        res += b[v];
        v -= lowbit(v);
    }
    return res;
}

void init(){
    int n = strlen(s+1);
    int m = strlen(t+1);

    for(int i = 1;i <= n;i++){
        update(bita,i,s[i]!='A',n);
        if(s[i] == 'A') pa[i] = pa[i-1]+1;
        else pa[i] = 0;
    }
    for(int i = 1;i <= m;i++){
        update(bitb,i,t[i]!='A',m);
        if(t[i] == 'A') pb[i] = pb[i-1]+1;
        else pb[i] = 0;
    }
}

int main(){
    scanf("%s%s",s+1,t+1);
    init();

    int T;
    scanf("%d",&T);
    int cnt = 0;
    while(T--){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int p = sum(bita,b) - sum(bita,a-1);
        int q = sum(bitb,d) - sum(bitb,c-1);
        if(p < q){
            if((q-p)&1) ans[cnt] = 0;
            else ans[cnt] = 1;
        }
        else if(p > q) ans[cnt] = 0;
        else {
            int k1 = min(pa[b],b-a+1);
            int k2 = min(pb[d],d-c+1);
            if(k1>=k2&&(k1 - k2)%3==0) ans[cnt] = 1;
            else ans[cnt] = 0;
        }
        cnt++;
    }
    for(int i = 0;i < cnt;i++) printf("%d",ans[i]);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10,mod = 1e9 + 7;
char s[maxn],t[maxn];
int bita[maxn],bitb[maxn],ans[maxn],pa[maxn],pb[maxn];

int lowbit(int x) {
    return x&-x;
}

void update(int b[],int v,int val,int up){
    while(v <= up){
        b[v] += val;
        v += lowbit(v);
    }
}

int sum(int b[],int v){
    int res = 0;
    while(v){
        res += b[v];
        v -= lowbit(v);
    }
    return res;
}

void init(){
    int n = strlen(s+1);
    int m = strlen(t+1);

    for(int i = 1;i <= n;i++){
        update(bita,i,s[i]!='A',n);
        if(s[i] == 'A') pa[i] = pa[i-1]+1;
        else pa[i] = 0;
    }
    for(int i = 1;i <= m;i++){
        update(bitb,i,t[i]!='A',m);
        if(t[i] == 'A') pb[i] = pb[i-1]+1;
        else pb[i] = 0;
    }
}

int main(){
    scanf("%s%s",s+1,t+1);
    init();

    int T;
    scanf("%d",&T);
    int cnt = 0;
    while(T--){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int p = sum(bita,b) - sum(bita,a-1);
        int q = sum(bitb,d) - sum(bitb,c-1);
        int k1 = min(pa[b],b-a+1);
        int k2 = min(pb[d],d-c+1);
        if(p < q){
            if((q-p)&1) ans[cnt] = 0;
            else {
                if(k1 >= k2) ans[cnt] = 1;
                else ans[cnt] = 0;
            }
        }
        else if(p > q) ans[cnt] = 0;
        else {
            if(k1>=k2&&(k1 - k2)%3==0) ans[cnt] = 1;
            else ans[cnt] = 0;
        }
        cnt++;
    }
    for(int i = 0;i < cnt;i++) printf("%d",ans[i]);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10,mod = 1e9 + 7;
char s[maxn],t[maxn];
int bita[maxn],bitb[maxn],ans[maxn],pa[maxn],pb[maxn];

int lowbit(int x) {
    return x&-x;
}

void update(int b[],int v,int val,int up){
    while(v <= up){
        b[v] += val;
        v += lowbit(v);
    }
}

int sum(int b[],int v){
    int res = 0;
    while(v){
        res += b[v];
        v -= lowbit(v);
    }
    return res;
}

void init(){
    int n = strlen(s+1);
    int m = strlen(t+1);

    for(int i = 1;i <= n;i++){
        update(bita,i,s[i]!='A',n);
        if(s[i] == 'A') pa[i] = pa[i-1]+1;
        else pa[i] = 0;
    }
    for(int i = 1;i <= m;i++){
        update(bitb,i,t[i]!='A',m);
        if(t[i] == 'A') pb[i] = pb[i-1]+1;
        else pb[i] = 0;
    }
}

int main(){
    scanf("%s%s",s+1,t+1);
    init();

    int T;
    scanf("%d",&T);
    int cnt = 0;
    while(T--){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int p = sum(bita,b) - sum(bita,a-1);
        int q = sum(bitb,d) - sum(bitb,c-1);
        if(p < q){
            if((q-p)&1) ans[cnt] = 0;
            else ans[cnt] = 1;
        }
        else if(p > q) ans[cnt] = 0;
        else {
            int k1 = min(pa[b],b-a+1);
            int k2 = min(pb[d],d-c+1);
            if(k1 == k2) ans[cnt] = 1;
            else ans[cnt] = 0;
        }
        cnt++;
    }
    for(int i = 0;i < cnt;i++) printf("%d",ans[i]);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10,mod = 1e9 + 7;
char s[maxn],t[maxn];
int bita[maxn],bitb[maxn],ans[maxn];

int lowbit(int x) {
    return x&-x;
}

void update(int b[],int v,int val,int up){
    while(v <= up){
        b[v] += val;
        v += lowbit(v);
    }
}

int sum(int b[],int v){
    int res = 0;
    while(v){
        res += b[v];
        v -= lowbit(v);
    }
    return res;
}

void init(){
    int n = strlen(s+1);
    int m = strlen(t+1);
    for(int i = 1;i <= n;i++){
        update(bita,i,s[i]!='A',n);
    }
    for(int i = 1;i <= m;i++){
        update(bitb,i,t[i]!='A',m);
    }
}

int main(){
    scanf("%s%s",s+1,t+1);
    init();
    int T;
    scanf("%d",&T);
    int cnt = 0;
    while(T--){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int p = sum(bita,b) - sum(bita,a-1);
        int q = sum(bitb,d) - sum(bitb,c-1);
        if(abs(p-q )&1) ans[cnt++] = 0;
        else ans[cnt++] = 1;
    }
    for(int i = 0;i < cnt;i++) printf("%d",ans[i]);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10,mod = 1e9 + 7;
char s[maxn],t[maxn];
int bita[maxn],bitb[maxn],ans[maxn],pa[maxn],pb[maxn];

int lowbit(int x) {
    return x&-x;
}

void update(int b[],int v,int val,int up){
    while(v <= up){
        b[v] += val;
        v += lowbit(v);
    }
}

int sum(int b[],int v){
    int res = 0;
    while(v){
        res += b[v];
        v -= lowbit(v);
    }
    return res;
}

void init(){
    int n = strlen(s+1);
    int m = strlen(t+1);

    for(int i = 1;i <= n;i++){
        update(bita,i,s[i]!='A',n);
        if(s[i] == 'A') pa[i] = pa[i-1]+1;
        else pa[i] = 0;
    }
    for(int i = 1;i <= m;i++){
        update(bitb,i,t[i]!='A',m);
        if(t[i] == 'A') pb[i] = pb[i-1]+1;
        else pb[i] = 0;
    }
}

int main(){
    scanf("%s%s",s+1,t+1);
    init();

    int T;
    scanf("%d",&T);
    int cnt = 0;
    while(T--){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int p = sum(bita,b) - sum(bita,a-1);
        int q = sum(bitb,d) - sum(bitb,c-1);
        int k1 = min(pa[b],b-a+1);
        int k2 = min(pb[d],d-c+1);
        if(p < q){
            if((q-p)&1) ans[cnt] = 0;
            else {
                if(p == 0){
                    ans[cnt] = (k1 > k2);
                }
                else{
                    if(k1 >= k2) ans[cnt] = 1;
                    else ans[cnt] = 0;
                }
            }
        }
        else if(p > q) ans[cnt] = 0;
        else {
            if(k1>=k2&&(k1 - k2)%3==0) ans[cnt] = 1;
            else ans[cnt] = 0;
        }
        cnt++;
    }
    for(int i = 0;i < cnt;i++) printf("%d",ans[i]);

    return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>//memset(a, 0, sizeof(a));

#define maxlongint 2147483647
#define ll long long
#define fo(i, x, y) for (int i = x; i <= y; i++)
#define fd(i, x, y) for (int i = x; i >= y; i--)
#define N 500005
using namespace std;
char S[N],T[N];
int a,b,c,d,n,m,Q;
int Sa[N],Sb[N],Ta[N],Tb[N];
int taS[N],taT[N];
int ans,leS,leT,TS,TT;
void read(int &x) {
	x=0;
	int k=1;char c=getchar();
	while ((c!='-')&&(c<'0'||c>'9')) c=getchar();
	if (c=='-') k=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	x=x*k;
}
void write(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
void init() {
	freopen("e.in","r",stdin);
	//freopen("e.out","w",stdout);
}
int main() {
	//init();
	scanf("%s\n",S);
	n=strlen(S);
	fo(i,1,n) {
		Sa[i]=Sa[i-1]+(S[i-1]=='A');
		Sb[i]=Sb[i-1]+(S[i-1]!='A');
		if (S[i-1]=='A') taS[i]=taS[i-1]+1;
	}
	scanf("%s\n",T);
	m=strlen(T);
	fo(i,1,m) {
		Ta[i]=Ta[i-1]+(T[i-1]=='A');
		Tb[i]=Tb[i-1]+(T[i-1]!='A');
		if (T[i-1]=='A') taT[i]=taT[i-1]+1;
	}
	read(Q);
	while (Q--) {
		read(a),read(b),read(c),read(d);
		ans=1;
		leS=Sb[b]-Sb[a-1],leT=Tb[d]-Tb[c-1];
		int dif=leT-leS;
		TS=min(taS[b],b-a+1),TT=min(taT[d],d-c+1);
		if (dif<0||TS<TT||dif%2) ans=0;
		if (dif<(TS-TT)%3*2) ans=0;
		if (Sb[b]==Sb[a-1]&&TS==TT&&dif) ans=0;
		write(ans);
	}
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>//memset(a, 0, sizeof(a));

#define maxlongint 2147483647
#define ll long long
#define fo(i, x, y) for (int i = x; i <= y; i++)
#define fd(i, x, y) for (int i = x; i >= y; i--)
#define N 500005
using namespace std;
char S[N],T[N];
int a,b,c,d,n,m,Q;
int Sa[N],Sb[N],Ta[N],Tb[N];
int taS[N],taT[N];
int ans,leS,leT,TS,TT;
void read(int &x) {
	x=0;
	int k=1;char c=getchar();
	while ((c!='-')&&(c<'0'||c>'9')) c=getchar();
	if (c=='-') k=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	x=x*k;
}
void write(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
void init() {
	freopen("e.in","r",stdin);
	//freopen("e.out","w",stdout);
}
int main() {
	init();
	scanf("%s\n",S);
	n=strlen(S);
	fo(i,1,n) {
		Sa[i]=Sa[i-1]+(S[i-1]=='A');
		Sb[i]=Sb[i-1]+(S[i-1]!='A');
		if (S[i-1]=='A') taS[i]=taS[i-1]+1;
	}
	scanf("%s\n",T);
	m=strlen(T);
	fo(i,1,m) {
		Ta[i]=Ta[i-1]+(T[i-1]=='A');
		Tb[i]=Tb[i-1]+(T[i-1]!='A');
		if (T[i-1]=='A') taT[i]=taT[i-1]+1;
	}
	read(Q);
	while (Q--) {
		read(a),read(b),read(c),read(d);
		ans=1;
		leS=Sb[b]-Sb[a-1],leT=Tb[d]-Tb[c-1];
		int dif=leT-leS;
		TS=min(taS[b],b-a+1),TT=min(taT[d],d-c+1);
		if (dif<0||TS<TT||dif%2) ans=0;
		if (dif<((TS-TT)%3>0)*2) ans=0;
		if (Sb[b]==Sb[a-1]&&TS==TT&&dif) ans=0;
		write(ans);
	}
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>//memset(a, 0, sizeof(a));

#define maxlongint 2147483647
#define ll long long
#define fo(i, x, y) for (int i = x; i <= y; i++)
#define fd(i, x, y) for (int i = x; i >= y; i--)
#define N 500005
using namespace std;
char S[N],T[N];
int a,b,c,d,n,m,Q;
int Sa[N],Sb[N],Ta[N],Tb[N];
int taS[N],taT[N];
int ans,leS,leT,TS,TT;
void read(int &x) {
	x=0;
	int k=1;char c=getchar();
	while ((c!='-')&&(c<'0'||c>'9')) c=getchar();
	if (c=='-') k=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	x=x*k;
}
void write(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
void init() {
	freopen("e.in","r",stdin);
	//freopen("e.out","w",stdout);
}
int main() {
	//init();
	scanf("%s\n",S);
	n=strlen(S);
	fo(i,1,n) {
		Sa[i]=Sa[i-1]+(S[i-1]=='A');
		Sb[i]=Sb[i-1]+(S[i-1]!='A');
		if (S[i-1]=='A') taS[i]=taS[i-1]+1;
	}
	scanf("%s\n",T);
	m=strlen(T);
	fo(i,1,m) {
		Ta[i]=Ta[i-1]+(T[i-1]=='A');
		Tb[i]=Tb[i-1]+(T[i-1]!='A');
		if (T[i-1]=='A') taT[i]=taT[i-1]+1;
	}
	read(Q);
	while (Q--) {
		read(a),read(b),read(c),read(d);
		ans=1;
		leS=Sb[b]-Sb[a-1],leT=Tb[d]-Tb[c-1];
		int dif=leT-leS;
		TS=min(taS[b],b-a+1),TT=min(taT[d],d-c+1);
		if (dif<0||TS<TT||dif%2) ans=0;
		if (dif<((TS-TT)%3>0)*2) ans=0;
		if (Sb[b]==Sb[a-1]&&TS==TT&&dif) ans=0;
		write(ans);
	}
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>//memset(a, 0, sizeof(a));

#define maxlongint 2147483647
#define ll long long
#define fo(i, x, y) for (int i = x; i <= y; i++)
#define fd(i, x, y) for (int i = x; i >= y; i--)
#define N 500005
using namespace std;
char S[N],T[N];
int a,b,c,d,n,m,Q;
int Sa[N],Sb[N],Ta[N],Tb[N];
int taS[N],taT[N];
int ans,leS,leT,TS,TT;
void read(int &x) {
	x=0;
	int k=1;char c=getchar();
	while ((c!='-')&&(c<'0'||c>'9')) c=getchar();
	if (c=='-') k=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	x=x*k;
}
void write(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
void init() {
	freopen("e.in","r",stdin);
	//freopen("e.out","w",stdout);
}
int main() {
	//init();
	scanf("%s\n",S);
	n=strlen(S);
	fo(i,1,n) {
		Sa[i]=Sa[i-1]+(S[i-1]=='A');
		Sb[i]=Sb[i-1]+(S[i-1]!='A');
		if (S[i-1]=='A') taS[i]=taS[i-1]+1;
	}
	scanf("%s\n",T);
	m=strlen(T);
	fo(i,1,m) {
		Ta[i]=Ta[i-1]+(T[i-1]=='A');
		Tb[i]=Tb[i-1]+(T[i-1]!='A');
		if (T[i-1]=='A') taT[i]=taT[i-1]+1;
	}
	read(Q);
	while (Q--) {
		read(a),read(b),read(c),read(d);
		ans=1;
		leS=Sb[b]-Sb[a-1],leT=Tb[d]-Tb[c-1];
		int dif=leT-leS;
		TS=min(taS[b],b-a+1),TT=min(taT[d],d-c+1);
		if (dif<0||TS<TT||dif%2) ans=0;
		//if (dif<(TS-TT)%3*2) ans=0;
		if ((TS-TT)%3) ans=0;
		if (Sb[b]==Sb[a-1]&&TS==TT&&dif) ans=0;
		write(ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int MaxLen = 100000;

int s[MaxLen + 1][2];
int t[MaxLen + 1][2];
int q;

void Get(int s[MaxLen][2])
{
	int c = 0;

	for (c = getchar(); (c == ' ') || (c == '\r') || (c == '\n'); c = getchar());

	for (int i = 1; (c == 'A') || (c == 'B') || (c == 'C'); c = getchar(), i++)
	{
		s[i][0] = s[i - 1][0];
		s[i][1] = s[i - 1][1];

		if (c != 'A')
		{
			s[i][0]++;
			s[i][1] = i + 1;
		}
	}
}

int main(int argc, char const *argv[])
{
	//freopen("init.in", "r", stdin);
	Get(s), Get(t);
	scanf("%d", &q);

	for (; q--;)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x = s[b][0] - s[a - 1][0], y = t[d][0] - t[c - 1][0];

		if ((x % 2) == (y % 2))
			if (x <= y)
				if (b - max(a, s[b][1]) >= d - max(c, t[d][1]))
				{
					printf("1");
					continue;
				}

		printf("0");
	}

	printf("\n");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int MaxLen = 100000;

int s[MaxLen + 1][2];
int t[MaxLen + 1][2];
int q;

void Get(int s[MaxLen][2])
{
	int c = 0;

	for (c = getchar(); (c == ' ') || (c == '\r') || (c == '\n'); c = getchar());

	for (int i = 1; (c == 'A') || (c == 'B') || (c == 'C'); c = getchar(), i++)
	{
		s[i][0] = s[i - 1][0];
		s[i][1] = s[i - 1][1];

		if (c != 'A')
		{
			s[i][0]++;
			s[i][1] = i + 1;
		}
	}
}

int main(int argc, char const *argv[])
{
	//freopen("init.in", "r", stdin);
	Get(s), Get(t);
	scanf("%d", &q);

	for (; q--;)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x = s[b][0] - s[a - 1][0], y = t[d][0] - t[c - 1][0];

		if ((x % 2) == (y % 2))
			if (x <= y)
				if (b - max(a, s[b][1]) == d - max(c, t[d][1]))
				{
					printf("1");
					continue;
				}

		printf("0");
	}

	printf("\n");
	return 0;
}