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

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



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

Input

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

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

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

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

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

Output

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

Example

Input

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


Output

10011

Note

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

The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.TreeSet;


public final class CF_VK_2018_R1{

	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}


	static long mod=1000000007;
	static long MX=1000000000000000001L;

	// Global vars
	static BufferedWriter out;
	static InputReader reader;

	static long powerMod(long b,long e,long m){
		long x=1;
		while (e>0) {
			if (e%2==1)
				x=(b*x)%m;
			b=(b*b)%m;
			e=e/2;
		}
		return x; 
	}


	/*
	rules
	0-> 11
	1-> 01
	111 -> .

	So we cannot add 0 at the end
	We can add any number of zeros before a 1
	number of 1 is stable %2
	
	*/
	
	
	static void process() throws Exception {


		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader=new InputReader(System.in);

		char[][] s=new char[2][];

		int[][] last=new int[2][];
		for (int e=0;e<2;e++) { 
			String ss=reader.readString();
			int L=ss.length();
			char[] c=new char[L];
			last[e]=new int[L];
			int cur=-1;
			for (int i=0;i<L;i++){
				if (ss.charAt(i)=='A')
					c[i]='0';
				else {
					c[i]='1';
					cur=i;
				}
				last[e][i]=cur;

			}
			s[e]=c;
		}



		int[][] num=new int[2][];
		for (int e=0;e<2;e++){
			int L=s[e].length;
			num[e]=new int[L];
			int cur=0;
			for (int i=0;i<L;i++){
				if (s[e][i]=='1')
					cur++;
				num[e][i]=cur;
			}

		}

		int Q=reader.readInt();
		int[] l=new int[2];
		int[] r=new int[2];
		
		char[] res=new char[Q];

		for (int q=0;q<Q;q++){
			//log("------");
			for (int e=0;e<2;e++){

				l[e]=reader.readInt()-1;
				r[e]=reader.readInt()-1;
				//log(s[e].substring(l[e],r[e]+1));

			}

			int ans=1;
			int[] cnt=new int[2];
			
		
			// number of ending '0'
			for (int e=0;e<2;e++){
				int x=r[e];
				if (s[e][x]=='0'){
					
					int i=last[e][x];
					if (i<l[e])
						i=l[e]-1;
					cnt[e]=x-i;
					
				}
				
			}
			
			int[] b=new int[2];
			for (int e=0;e<2;e++){
				b[e]=num[e][r[e]];
				if (l[e]>0)
					b[e]-=num[e][l[e]-1];
			}
			
			// numbero 1 cannot be lower nor different %2
			if (b[1]<b[0] || b[1]%2!=b[0]%2)
				ans=0;
	
			// number of ending zeros cannot be bigger
			if (cnt[1]>cnt[0])
				ans=0;
			else {
				if (cnt[0]==cnt[1]){
					// we have an issue only if we have to generate a 1 from 0...
					// because we need to sacrifice a zero
					if (b[0]==0 && b[1]>0)
						ans=0;
				} else {
					// we have more
					// it's ok if either we have right modulo or we have b to generate
					if (cnt[0]%3!=cnt[1]%3 && b[1]==b[0])
						ans=0;
					
				}
				
			}
			
			res[q]=(char)('0'+ans);
				
		
		}
		//log("");
		output(new String(res));


	
		try {
			out.close();
		}
		catch (Exception EX){}


	}


	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}


		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res=new StringBuilder();
			do {
				res.append((char)c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}




		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}


}