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.*;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            String filename = "";
            if (!filename.isEmpty()) {
                in = new BufferedReader(new FileReader(filename + ".in"));
                out = new PrintWriter(filename + ".out");
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readLongArray(int size) throws IOException {
        long[] res = new long[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
//        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    int[] pref(char[] a) {
        int[] p = new int[a.length + 1];
        for (int i = 0; i < a.length; i++) {
            p[i + 1] = p[i] + (a[i] != 'A' ? 1 : 0);
        }
        return p;
    }

    int[] coutnA(char[] a) {
        int[] cnt = new int[a.length + 1];
        for (int i = 0; i < a.length; i++) {
            if (a[i] == 'A') {
                cnt[i + 1] = cnt[i] + 1;
            } else {
                cnt[i + 1] = 0;
            }
        }
        return cnt;
    }

    private void solve() throws IOException {
        char[] s = readString().toCharArray();
        char[] t = readString().toCharArray();
        int[] prefS = pref(s);
        int[] prefT = pref(t);

        int[] cntAS = coutnA(s);
        int[] cntAT = coutnA(t);

        int m = readInt();

        for (int i = 0; i < m; i++) {
            int a = readInt(), b = readInt(), c = readInt(), d = readInt();

            int cntBS = prefS[b] - prefS[a - 1];
            int cntBT = prefT[d] - prefT[c - 1];
            int len1 = b - a + 1;
            int len2 = d - c + 1;
            out.print(solve(cntBS, cntBT, Math.min(len1, cntAS[b]), Math.min(cntAT[d], len2)));
        }

    }

    int solve(int cntBS, int cntBT, int cntAS, int cntAT) {
        if (cntBS % 2 != cntBT % 2) return 0;
        if (cntBS > cntBT) return 0;
        if (cntBS == cntBT) {
            if (cntAS == cntAT) return 1;
            if (cntAS < cntAT) return 0;
            return (cntAS - cntAT) % 3 == 0 ? 1 : 0;
        }
        if (cntBS == 0) {
            if (cntAS - 1 < cntAT) return 0;
        }
        if (cntAS < cntAT) return 0;
        return 1;
    }


}



