import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;

public class Main {
     FastScanner in = new FastScanner(System.in);
     PrintWriter out = new PrintWriter(System.out);
     public static void main(String[]args){
         new Main().solve();
     }

     void solve(){
         int[][]tab = new int[8][8];
         int[][]black = new int[8][8];
         String a = in.next();
         String b = in.next();
         String v = in.next();
         String n = in.next();

         char c = v.charAt(0);
         int x = 0;
         int y = Integer.parseInt( "" + v.charAt(1))-1;
         if (c=='a'){x = 0;}
         if (c=='b'){x = 1;}
         if (c=='c'){x = 2;}
         if (c=='d'){x = 3;}
         if (c=='e'){x = 4;}
         if (c=='f'){x = 5;}
         if (c=='g'){x = 6;}
         if (c=='h'){x = 7;}
         tab[x][y] = 9;
         int tmpx = -1, tmpy = -1;

         tmpx = x-1;
         tmpy = y-1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             tab[tmpx][tmpy] = 9;
         }

         tmpx = x-1;
         tmpy = y;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             tab[tmpx][tmpy] = 9;
         }

         tmpx = x-1;
         tmpy = y+1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             tab[tmpx][tmpy] = 9;
         }

         tmpx = x;
         tmpy = y-1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             tab[tmpx][tmpy] = 9;
         }

         tmpx = x;
         tmpy = y + 1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             tab[tmpx][tmpy] = 9;
         }

         tmpx = x+1;
         tmpy = y;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             tab[tmpx][tmpy] = 9;
         }

         tmpx = x+1;
         tmpy = y+1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             tab[tmpx][tmpy] = 9;
         }

         tmpx = x+1;
         tmpy = y-1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             tab[tmpx][tmpy] = 9;
         }
         tab[x][y] = 1;
         c = a.charAt(0);
         x = 0;
         y = Integer.parseInt( "" + a.charAt(1))-1;
         if (c=='a'){x = 0;}
         if (c=='b'){x = 1;}
         if (c=='c'){x = 2;}
         if (c=='d'){x = 3;}
         if (c=='e'){x = 4;}
         if (c=='f'){x = 5;}
         if (c=='g'){x = 6;}
         if (c=='h'){x = 7;}
         tab[x][y] = 9;
         for (int i = 0; i<8; i++){
             if (tab[i][y] == 1)break;
             else tab[i][y] = 9;
         }
         for (int i = 0; i<8; i++){
             if (tab[x][i] == 1)break;
             else tab[x][i] = 9;
         }
         tab[x][y] = 1;

         c = b.charAt(0);
         x = 0;
         y = Integer.parseInt( "" + b.charAt(1))-1;
         if (c=='a'){x = 0;}
         if (c=='b'){x = 1;}
         if (c=='c'){x = 2;}
         if (c=='d'){x = 3;}
         if (c=='e'){x = 4;}
         if (c=='f'){x = 5;}
         if (c=='g'){x = 6;}
         if (c=='h'){x = 7;}
         tab[x][y] = 9;
         for (int i = 0; i<8; i++){
             if (tab[i][y] == 1)break;
             else tab[i][y] = 9;
         }
         for (int i = 0; i<8; i++){
             if (tab[x][i] == 1)break;
             else tab[x][i] = 9;
         }
         tab[x][y] = 1;

         ///////////////
         c = n.charAt(0);
         x = 0;
         y = Integer.parseInt( "" + n.charAt(1))-1;
         if (c=='a'){x = 0;}
         if (c=='b'){x = 1;}
         if (c=='c'){x = 2;}
         if (c=='d'){x = 3;}
         if (c=='e'){x = 4;}
         if (c=='f'){x = 5;}
         if (c=='g'){x = 6;}
         if (c=='h'){x = 7;}
         black[x][y] = 5;
         tmpx = -1; tmpy = -1;

         tmpx = x-1;
         tmpy = y-1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             black[tmpx][tmpy] = 5;
         }

         tmpx = x-1;
         tmpy = y;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             black[tmpx][tmpy] = 5;
         }

         tmpx = x-1;
         tmpy = y+1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             black[tmpx][tmpy] = 5;
         }

         tmpx = x;
         tmpy = y-1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             black[tmpx][tmpy] = 5;
         }

         tmpx = x;
         tmpy = y + 1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             black[tmpx][tmpy] = 5;
         }

         tmpx = x+1;
         tmpy = y;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             black[tmpx][tmpy] = 5;
         }

         tmpx = x+1;
         tmpy = y+1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             black[tmpx][tmpy] = 5;
         }

         tmpx = x+1;
         tmpy = y-1;
         if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){
             black[tmpx][tmpy] = 5;
         }
         ////
         boolean f = false;
         for (int i = 0; i<8; i++){
             for (int j = 0; j<8; j++){
                 if (black[i][j]==5){
                     if (tab[i][j]==1 || tab[i][j]==0)f = true;;
                 }
             }
         }
         if (f)System.out.println("OTHER");
         else System.out.println("CHECKMATE");
//       for(int i = 0; i<8; i++){
//           for (int j = 0; j < 8; j++) {
//               System.out.print(tab[i][j]+" ");
//          }System.out.println();
//       }
//       System.out.println();
//       for(int i = 0; i<8; i++){
//           for (int j = 0; j < 8; j++) {
//               System.out.print(black[i][j]+" ");
//          }System.out.println();
//       }
     }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    System.err.println(e);
                    return "";
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        float nextFloat(){
            return Float.parseFloat(next());
        }
        BigInteger nextBigInt(){
            return new BigInteger(next());
        }
        void close() {
            try {
                br.close();
            }
            catch (IOException e) {
            }
        }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class B implements Runnable {
	public static void main(String[] args) {
		new B().run();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		boolean eof;
		String buf;

		public FastScanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
			nextToken();
		}

		public FastScanner(InputStream stream) {
			br = new BufferedReader(new InputStreamReader(stream));
			nextToken();
		}

		String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		BigInteger nextBigInteger() {
			return new BigInteger(nextToken());
		}

		void close() {
			try {
				br.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	BigInteger nextBigInteger() {
		return sc.nextBigInteger();
	}

	void solve() {
		String s1 = nextToken();
		String s2 = nextToken();
		String s3 = nextToken();
		String s4 = nextToken();
		int x1 = s1.charAt(0) - 'a';
		int y1 = s1.charAt(1) - '1';
		int x2 = s2.charAt(0) - 'a';
		int y2 = s2.charAt(1) - '1';
		int x3 = s3.charAt(0) - 'a';
		int y3 = s3.charAt(1) - '1';
		int x4 = s4.charAt(0) - 'a';
		int y4 = s4.charAt(1) - '1';
		boolean[][] has = new boolean[8][8];
		has[x1][y1] = has[x2][y2] = has[x3][y3] = true;
		for (int dx = -1; dx <= 1; dx++) {
			for (int dy = -1; dy <= 1; dy++) {
				int x = x4 + dx;
				int y = y4 + dy;
				boolean ok1 = (check1(has, x1, y1, x, y));
				boolean ok2 = (check1(has, x2, y2, x, y));
				boolean ok3 = (check2(has, x3, y3, x, y));
				if (ok1 || ok2 || ok3) {
					continue;
				}
				out.println("OTHER");
				return;
			}
		}
		out.println("CHECKMATE");
	}

	boolean check2(boolean[][] has, int x, int y, int x1, int y1) {
		if (x == x1 && y == y1) {
			return false;
		}
		return (Math.abs(x - x1) <= 1 && Math.abs(y - y1) <= 1);
	}

	boolean check1(boolean[][] has, int x, int y, int x1, int y1) {
		if ((x1 != x && y1 != y) || (x == x1 && y == y1)) {
			return false;
		}
		int dx;
		int dy;
		if (x1 == x) {
			dx = 0;
			dy = y1 < y ? -1 : 1;
		} else {
			dx = x1 < x ? -1 : 1;
			dy = 0;
		}
		int xx = x + dx;
		int yy = y + dy;
		while (xx >= 0 && yy >= 0 && xx < 8 && yy < 8 && !has[xx][yy]) {
			if (xx == x1 && yy == y1) {
				return true;
			}
			xx += dx;
			yy += dy;
		}
		return xx == x1 && yy == y1;
	}
}


import java.io.*;
import java.util.*;
import java.math.*;

public class B implements Runnable {
	public static void main(String[] args) {
		new B().run();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		boolean eof;
		String buf;

		public FastScanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
			nextToken();
		}

		public FastScanner(InputStream stream) {
			br = new BufferedReader(new InputStreamReader(stream));
			nextToken();
		}

		String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		BigInteger nextBigInteger() {
			return new BigInteger(nextToken());
		}

		void close() {
			try {
				br.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	BigInteger nextBigInteger() {
		return sc.nextBigInteger();
	}

	void solve() {
		String s1 = nextToken();
		String s2 = nextToken();
		String s3 = nextToken();
		String s4 = nextToken();
		int x1 = s1.charAt(0) - 'a';
		int y1 = s1.charAt(1) - '1';
		int x2 = s2.charAt(0) - 'a';
		int y2 = s2.charAt(1) - '1';
		int x3 = s3.charAt(0) - 'a';
		int y3 = s3.charAt(1) - '1';
		int x4 = s4.charAt(0) - 'a';
		int y4 = s4.charAt(1) - '1';
		boolean[][] has = new boolean[8][8];
		has[x1][y1] = has[x2][y2] = has[x3][y3] = true;
		for (int dx = -1; dx <= 1; dx++) {
			for (int dy = -1; dy <= 1; dy++) {
				int x = x4 + dx;
				int y = y4 + dy;
				boolean ok1 = (check1(has, x1, y1, x, y));
				boolean ok2 = (check1(has, x2, y2, x, y));
				boolean ok3 = (check2(has, x3, y3, x, y));
				if (ok1 || ok2 || ok3) {
					continue;
				}
				out.println("OTHER");
				return;
			}
		}
		out.println("CHECKMATE");
	}

	boolean check2(boolean[][] has, int x, int y, int x1, int y1) {
		if (x == x1 && y == y1) {
			return false;
		}
		if (Math.abs(x - x1) <= 1 && Math.abs(y - y1) <= 1) {
			return false;
		}
		return true;
	}

	boolean check1(boolean[][] has, int x, int y, int x1, int y1) {
		if ((x1 != x && y1 != y) || (x == x1 && y == y1)) {
			return false;
		}
		int dx;
		int dy;
		if (x1 == x) {
			dx = 0;
			dy = y1 < y ? -1 : 1;
		} else {
			dx = x1 < x ? -1 : 1;
			dy = 0;
		}
		int xx = x + dx;
		int yy = y + dy;
		while (xx >= 0 && yy >= 0 && xx < 8 && yy < 8 && !has[xx][yy]) {
			if (xx == x1 && yy == y1) {
				return true;
			}
			xx += dx;
			yy += dy;
		}
		return xx == x1 && yy == y1;
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class E {
    static int n;
    static int m;
    static int[][][] DP;
    static int[] dx = { 0, 0, 1, -1 };
    static int[] dy = { 1, -1, 0, 0 };
    static int inf = 1000000;

    public static int get(int x, int current, int last) {
        if (x == n) {
            if (last == 0)
                return 0;
            else
                return -inf;
        }
        if (DP[x][current][last] != -1)
            return DP[x][current][last];
        int max = 0;
        for (int mask = 0; mask < (1 << m); mask++) {
            int tempLast = last;
            int tempCurrent = current;
            int tempNext = (1 << m) - 1;
            for (int i = 0; i < m; i++)
                if ((mask & (1 << i)) != 0) {
                    if (i > 0)
                        tempCurrent &= ~(1 << (i - 1));
                    if (i < m - 1)
                        tempCurrent &= ~(1 << (i + 1));
                    tempNext &= ~(1 << (i));
                    tempLast &= ~(1 << (i));
                }
            if (tempLast != 0)
                continue;
            max = Math.max(
                    max,
                    m - Integer.bitCount(mask)
                            + get(x + 1, tempNext, tempCurrent & ~mask));
        }
        return DP[x][current][last] = max;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        n = Math.max(x, y);
        m = Math.min(x, y);
        DP = new int[n][1 << m][1 << m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < (1 << m); j++)
                Arrays.fill(DP[i][j], -1);
        System.out.println(get(0, (1 << m) - 1, 0));
    }
}
package Rnd85;

import java.util.Arrays;
import java.util.Scanner;

public class E {
    static int n;
    static int m;
    static int[][][] DP;
    static int[] dx = { 0, 0, 1, -1 };
    static int[] dy = { 1, -1, 0, 0 };
    static int inf = 1000000;

    public static int get(int x, int current, int last) {
        if (x == n) {
            if (last == 0)
                return 0;
            else
                return -inf;
        }
        if (DP[x][current][last] != -1)
            return DP[x][current][last];
        int max = 0;
        for (int mask = 0; mask < (1 << m); mask++) {
            int tempLast = last;
            int tempCurrent = current;
            int tempNext = (1 << m) - 1;
            for (int i = 0; i < m; i++)
                if ((mask & (1 << i)) != 0) {
                    if (i > 0)
                        tempCurrent &= ~(1 << (i - 1));
                    if (i < m - 1)
                        tempCurrent &= ~(1 << (i + 1));
                    tempNext &= ~(1 << (i));
                    tempLast &= ~(1 << (i));
                }
            if (tempLast != 0)
                continue;
            max = Math.max(
                    max,
                    m - Integer.bitCount(mask)
                            + get(x + 1, tempNext, tempCurrent & ~mask));
        }
        return DP[x][current][last] = max;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        n = Math.max(x, y);
        m = Math.min(x, y);
        DP = new int[n][1 << m][1 << m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < (1 << m); j++)
                Arrays.fill(DP[i][j], -1);
        System.out.println(get(0, (1 << m) - 1, 0));
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);

        int n = r.nextInt();
        int m = r.nextInt(import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);

        int n = r.nextInt();
        int m = r.nextInt();

        if(n > m){int t = n; n = m; m = t;}

        dp = new int[m+1][1 << 7][1 << 7];
        for(int[][] i : dp)
            for(int[] j : i)
                Arrays.fill(j, -1);
        int min = go(m, 0, (1<<n) -1, n, m);

        System.out.println(n * m - min);
    }
    static int[][][] dp;
    private static int go(int rem, int prev, int need, int n, int m) {
//      for(int i = rem; i < m; i++)
//          System.out.print(" ");
//      System.out.println(rem + ": " + prev +","+need);
        if(rem == 0)return prev == 0?0:1 << 20;
        if(dp[rem][prev][need] != -1)return dp[rem][prev][need];

        int min = 1 << 20;
        for(int now = 0; now < 1 << n; now++){
            if((~now & prev) != 0)continue;

            int after = need & ~(now) & ~(now << 1) & ~(now >> 1);
            int next = ~(now) & ((1 << n)-1);
            int current = Integer.bitCount(now) + go(rem-1, after ,next, n, m);
            min = Math.min(min, current);
        }
        return dp[rem][prev][need] = min;
    }
}
);

        if(n > m){int t = n; n = m; m = t;}

        dp = new int[m+1][1 << 7][1 << 7];
        int min = go(m, 0, (1<<n) -1, n, m);

        System.out.println(n * m - min);
    }
    static int[][][] dp;
    private static int go(int rem, int prev, int need, int n, int m) {
//      for(int i = rem; i < m; i++)
//          System.out.print(" ");
//      System.out.println(rem + ": " + prev +","+need);
        if(rem == 0)return prev == 0?0:1 << 20;
        if(dp[rem][prev][need] != -1)return dp[rem][prev][need];

        int min = 1 << 20;
        for(int now = 0; now < 1 << n; now++){
            if((~now & prev) != 0)continue;

            int after = need & ~(now) & ~(now << 1) & ~(now >> 1);
            int next = ~(now) & ((1 << n)-1);

            int current = Integer.bitCount(now) + go(rem-1, after ,next, n, m);
            min = Math.min(min, current);
        }
        return dp[rem][prev][need] = min;
    }
}


import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class P111C{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int h, w;

	void run(){
		h=sc.nextInt();
		w=sc.nextInt();
		solve();
	}

	void solve(){
		n=w*h;
		g=new long[n];
		int[] dx={0, 0, -1, 1};
		int[] dy={-1, 1, 0, 0};
		for(int y=0; y<h; y++){
			for(int x=0; x<w; x++){
				for(int k=0; k<4; k++){
					int x2=x+dx[k];
					int y2=y+dy[k];
					if(x2>=0&&x2<w&&y2>=0&&y2<h){
						g[y*w+x]|=1L<<(y2*w+x2);
					}
				}
			}
		}
		mds=(1L<<n)-1;
		mds(0, 0, 0);
		println((n-Long.bitCount(mds))+"");
	}

	int n;
	long[] g;
	long mds;

	void mds(long choosed, long removed, long covered){
		if(Long.bitCount(choosed)>=Long.bitCount(mds))
			return;
		if(covered==((1L<<n)-1)){
			if(Long.bitCount(choosed)<Long.bitCount(mds))
				mds=choosed;
			return;
		}

		int k=-1;
		for(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){
			int i=Long.numberOfTrailingZeros(remained);
			if((covered>>>i&1)==1){
				if(Long.bitCount(g[i]&~covered)==0){
					mds(choosed, removed|(1L<<i), covered);
					return;
				}else if(Long.bitCount(g[i]&~covered)==1
						&&(g[i]&~covered&~removed)!=0){
					mds(choosed, removed|(1L<<i), covered);
					return;
				}
			}else{
				if(Long.bitCount(g[i]&~removed)==0){
					mds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);
					return;
				}else if(Long.bitCount(g[i]&~removed)==1
						&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){
					int j=Long.numberOfTrailingZeros(g[i]&~removed);
					mds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered
							|(1L<<j)|g[j]);
					return;
				}
			}
			if(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered))
				k=i;
		}
		if(k==-1)
			return;

		mds(choosed|(1L<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);
		mds(choosed, removed|(1L<<k), covered);
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args){
		Locale.setDefault(Locale.US);
		new P111C().run();
	}
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (Throwable e) {
					e.printStackTrace();
					exit(999);
				}
			}
		}, "1", 1 << 23).start();
	}

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

	int n, m;
	int dp[][][];
	int MV = Integer.MAX_VALUE >> 1;
	int ans = MV;

	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		n = nextInt();
		m = nextInt();
		if(n < m){ int d = n; n = m; m = d; }
		int M = 1 << m;
		dp = new int[n][m << 1][ m << 1];
		for(int a[][] : dp)
			for(int b[] : a)
				fill(b, MV);

//		for(int i = 0 ; i < M; i++){
//			int next = (( i | (i << 1) | (i >> 1) ) & (M - 1));
//			if(  next!= (M -1))
//				continue;
//			if(n > 1)
//				dp[0][next][0] = Integer.bitCount(i);
//			else
//				ans = min(ans, Integer.bitCount(i));
//		}
		dp[0][0][0] = 0;

		for(int i = 0; i < n; i++)
			for(int m1 = 0; m1 < M; m1++)
				for(int m2 = 0; m2 < M; m2++){
					if(dp[i][m1][m2] == MV)
						continue;
					for(int nm1 = 0; nm1 < M; nm1++)
						for(int nm2 = 0; nm2 < M; nm2++){
							int res1 = m1 | (nm1) | (nm1 << 1) | (nm1 >> 1) | (nm2);
							res1 &= (M - 1);

							if(res1 != (M - 1))
								continue;

							int res2 = m2 | (nm1) | (nm2 << 1) | (nm2 >> 1) | (nm2);
							res2 &= (M - 1);

//							if(i == 2 && m1 == 3 && m2 == 2 && nm1 == 0 && nm2 == 0){
//								System.err.println("kek");
//								System.err.println(dp[i][m1][m2]);
//								System.err.println(res1 + " | " + res2);
//								System.err.println(M);
//							}

							int next1 = res2 & (M - 1);
							int next2 = nm2 & ( M - 1);
							int over = Integer.bitCount(nm1) + Integer.bitCount(nm2);

							if(i < n - 1)
								dp[i+1][next1][next2] = min(dp[i + 1][next1][next2], dp[i][m1][m2] + over);
							else
								if((res1 & (M - 1)) == (M - 1)){
									ans = min(dp[i][m1][m2] + over, ans);
								}
						}

				}
//		System.err.println(ans);
		out.println(n * m - ans);

		in.close();
		out.close();
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


package main;

import lib.InputReader;
import java.io.PrintWriter;

public class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        String s = in.next();

        out.println(s.replaceAll("o(go)+","***"));
    }
}


import java.util.*;
public class Test
{
    public static void main(String [] args)
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        String str = s.next();
        if(str.contains("ogogogo"))
        {
            String st = str.replace("ogogogo","***");
        }
        else if(str.contains("ogogo"))
        {
            String st =  str.replace("ogogo","***");
        }
        else if(str.contains("ogo"))
        {
            String st = str.replace("ogo","***");
        }
        System.out.println(st);
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.InputMismatchException;

public class P1 {

  public static void main(String[] args) {
    // TODO Auto-generated method stub
    FastReader sc = new FastReader(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    boolean found = false;
    int i=0;
    for(i=0;i<s.length();i++){
       if(found){
         while(i+1 < s.length()  && s.charAt(i) == 'g' && s.charAt(i+1) == 'o'){
           StringBuilder str = new StringBuilder(s);
           str.delete(i, i+2);
           s = str.toString();

         }
         found = false;
       }
       if(i<s.length() && s.charAt(i) == 'o'){
           if(i+3 <= s.length()) {
             String s1 = s.substring(i, i+3);
             if(s1.equalsIgnoreCase("ogo")){
                  StringBuilder sb = new StringBuilder(s);
                  sb.replace(i, i+3, "***");
                  s = sb.toString();
                  i = i+2;
                 found = true;
             }
           }
       }
    }
    System.out.println(s);
  }

}

class FastReader3 {
private boolean finished = false;

private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;

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

public int read() {
  if (numChars == -1) {
      throw new InputMismatchException();
  }
  if (curChar >= numChars) {
      curChar = 0;
      try {
          numChars = stream.read(buf);
      } catch (IOException e) {
          throw new InputMismatchException();
      }
      if (numChars <= 0) {
          return -1;
      }
  }

  return buf[curChar++];
}

public int peek() {
  if (numChars == -1) {
      return -1;
  }
  if (curChar >= numChars) {
      curChar = 0;
      try {
          numChars = stream.read(buf);
      } catch (IOException e) {
          return -1;
      }
      if (numChars <= 0) {
          return -1;
      }
  }
  return buf[curChar];
}

public int nextInt() {
  int c = read();
  while (isSpaceChar(c))
      c = read();
  int sgn = 1;
  if (c == '-') {
      sgn = -1;
      c = read();
  }
  int res = 0;
  do {
      if (c == ',') {
          c = read();
      }
      if (c < '0' || c > '9') {
          throw new InputMismatchException();
      }
      res *= 10;
      res += c - '0';
      c = read();
  } while (!isSpaceChar(c));
  return res * sgn;
}

public long nextLong() {
  int c = read();
  while (isSpaceChar(c))
      c = read();
  int sgn = 1;
  if (c == '-') {
      sgn = -1;
      c = read();
  }
  long res = 0;
  do {
      if (c < '0' || c > '9') {
          throw new InputMismatchException();
      }
      res *= 10;
      res += c - '0';
      c = read();
  } while (!isSpaceChar(c));
  return res * sgn;
}

public String nextString() {
  int c = read();
  while (isSpaceChar(c))
      c = read();
  StringBuilder res = new StringBuilder();
  do {
      res.appendCodePoint(c);
      c = read();
  } while (!isSpaceChar(c));
  return res.toString();
}

public boolean isSpaceChar(int c) {
  if (filter != null) {
      return filter.isSpaceChar(c);
  }
  return isWhitespace(c);
}

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

private String readLine0() {
  StringBuilder buf = new StringBuilder();
  int c = read();
  while (c != '\n' && c != -1) {
      if (c != '\r') {
          buf.appendCodePoint(c);
      }
      c = read();
  }
  return buf.toString();
}

public String nextLine() {
  String s = readLine0();
  while (s.trim().length() == 0)
      s = readLine0();
  return s;
}

public String nextLine(boolean ignoreEmptyLines) {
  if (ignoreEmptyLines) {
      return nextLine();
  } else {
      return readLine0();
  }
}

public BigInteger nextBigInteger() {
  try {
      return new BigInteger(nextString());
  } catch (NumberFormatException e) {
      throw new InputMismatchException();
  }
}

public char nextCharacter() {
  int c = read();
  while (isSpaceChar(c))
      c = read();
  return (char) c;
}

public double nextDouble() {
  int c = read();
  while (isSpaceChar(c))
      c = read();
  int sgn = 1;
  if (c == '-') {
      sgn = -1;
      c = read();
  }
  double res = 0;
  while (!isSpaceChar(c) && c != '.') {
      if (c == 'e' || c == 'E') {
          return res * Math.pow(10, nextInt());
      }
      if (c < '0' || c > '9') {
          throw new InputMismatchException();
      }
      res *= 10;
      res += c - '0';
      c = read();
  }
  if (c == '.') {
      c = read();
      double m = 1;
      while (!isSpaceChar(c)) {
          if (c == 'e' || c == 'E') {
              return res * Math.pow(10, nextInt());
          }
          if (c < '0' || c > '9') {
              throw new InputMismatchException();
          }
          m /= 10;
          res += (c - '0') * m;
          c = read();
      }
  }
  return res * sgn;
}

public boolean isExhausted() {
  int value;
  while (isSpaceChar(value = peek()) && value != -1)
      read();
  return value == -1;
}

public String next() {
  return nextString();
}

public SpaceCharFilter getFilter() {
  return filter;
}

public void setFilter(SpaceCharFilter filter) {
  this.filter = filter;
}

public interface SpaceCharFilter {
  public boolean isSpaceChar(int ch);
}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class hi{

    public static void main(String[] args)  {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        boolean ok = false;
        boolean o = false;
        boolean g = false;
        for(int i=0;i<n;i++){
            if(s.charAt(i)=='o'){
                if(o && g) {
                    ok = true;
                    g = false;
                }
                else if(!o) o = true;
                else {
                    if(ok) System.out.print("***");
                    else{
                        System.out.print("o");
                    }
                    ok = false;
                    g = false;
                }

            }
            else if(s.charAt(i)=='g'){
                if(o && !g) g = true;
                else if(!o){
                    System.out.print("g");

                }
                else{
                    if(ok) System.out.print("***");
                    else System.out.print("o");
                    System.out.print("gg");
                    g = false;
                    o = false;
                    ok = false
                }
            }else{

                if(ok) System.out.print("***");
                else {
                    if(o) System.out.print("o");
                }
                if(g) System.out.print("g");
                ok = false;
                o = false;
                g = false;
                System.out.print(s.charAt(i));
            }
        }
        if(ok) System.out.print("***");

    }

}


import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class test{
    Scanner in;
    PrintWriter out;
    boolean[] v;
    List<Integer>[] vec = new ArrayList[23];
    boolean vis[] = new boolean[23];
    int[] deg = new int[23];
    int tp;

    void solve()
    {
        int n = in.nextInt();
        int m = in.nextInt();

        for(int i=1;i<=n;i++)
            vec[i] = new ArrayList<Integer>();

        for(int i=1;i<=m;i++){
            int ta,tb;
            ta = in.nextInt();
            tb = in.nextInt();
            if(ta==tb)
                continue;
            if(vec[ta].contains(tb))
                continue;

            vec[ta].add(tb);
            vec[tb].add(ta);
            deg[ta]++;deg[tb]++;
        }

        for(int i=1;i<=n;i++){
            Collections.sort(vec[i], new Comparator<Integer>() {
                @Override
                public int compare(Integer x, Integer y) {
                    if(deg[x]==deg[y])
                        return x-y;
                    return deg[x]-deg[y];
                }
            });
        }

        for (int i=1;i<=n;i++){
            Arrays.fill(vis, false);
            tp=0;
            dfs(i);
            if (tp==n){
                out.print("Yes");
                return;
            }
        }
       out.print("No");

    }

    void dfs(int cur){
        vis[cur]=true;
        tp++;
        int vsize=vec[cur].size();
        for (int i=0;i<vsize;i++){
            int u=vec[cur].get(i);
            if (!vis[u])
            {dfs(u);return;}
        }
    }

    void run() throws Exception
    {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new test().run(); }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.util.*;
public class j {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt(), m = input.nextInt();
    boolean[][] adj = new boolean[n][n];
    for(int i = 0; i<m; i++)
    {
        int a = input.nextInt()-1, b = input.nextInt()-1;
        if(a!=b)
        adj[a][b] = adj[b][a] = true;
    }
    ArrayList<Integer>[] graph = new ArrayList[n];
    int[] degrees = new int[n];
    for(int i = 0; i<n; i++)
    {
        graph[i] = new ArrayList<Integer>();
        for(int j =0; j<n; j++) if(adj[i][j])
        {
            graph[i].add(j);
            degrees[i]++;
        }
    }
    int[] sorted = new int[n];
    int index = 0;
    for(int i = n; i>=0;i--)
        for(int j = 0; j<n; j++)
            if(degrees[j] == i)
                sorted[j] = index++;
    boolean good = false;
    for(int i = 0; i<n; i++)
    {
        boolean[] visited = new boolean[n];
        int at = i;
        int count = 1;
        visited[i] = true;
        while(true)
        {
            int togo = -1;
            for(int j = 0; j<graph[at].size(); j++)
                if(!visited[graph[at].get(j)] && (togo==-1 || sorted[graph[at].get(j)] < sorted[togo]))
                    togo = graph[at].get(j);
            if(togo != -1)
            {
                count++;
                at = togo;
                visited[togo] = true;
            }
            else
                break;
        }
        if(count==n) good = true;
    }
    System.out.println(good?"Yes":"No");
}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class F {

	public static void main(String[] args) throws IOException {
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt(), m = scan.nextInt();
		ArrayList<Integer>[] adj = new ArrayList[n];
		for(int i = 0; i < n; i++) adj[i] = new ArrayList<Integer>();
		for(int i = 0; i < m; i++) adj[scan.nextInt()-1].add(scan.nextInt()-1);
		boolean res = false;
		for(int i = 0; i < n; i++) res |= go(i, adj, n, new boolean[n], 0);
		out.println(res?"Yes":"No");
		out.close();
	}

	static boolean go(int at, ArrayList<Integer>[] adj, int n, boolean[] v, int c){
		v[at] = true;
		c++;
		if(c == n) return true;
		boolean res = false;
		for(int i : adj[at]) if(!v[i])res |= go(i, adj, n, v, c);
		v[at] = false;
		return res;
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e){e.printStackTrace();}
		}

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}

		public int nextInt() {return Integer.parseInt(next());}

		public long nextLong() {return Long.parseLong(next());}

		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			try {line = br.readLine();}
			catch (Exception e) {e.printStackTrace();}
			return line;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a = new long[n];
			for(int i = 0; i < n; i++) a[i] = nextLong();
			return a;
		}

		public double[] nextDoubleArray(int n){
			double[] a = new double[n];
			for(int i = 0; i < n; i++) a[i] = nextDouble();
			return a;
		}

		public char[][] nextGrid(int n, int m){
			char[][] grid = new char[n][m];
			for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
			return grid;
		}
	}

}


import java.util.*;
public class j {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt(), m = input.nextInt();
    boolean[][] adj = new boolean[n][n];
    for(int i = 0; i<m; i++)
    {
        int a = input.nextInt()-1, b = input.nextInt()-1;
        if(a!=b)
        adj[a][b] = adj[b][a] = true;
    }
    ArrayList<Integer>[] graph = new ArrayList[n];
    int[] degrees = new int[n];
    for(int i = 0; i<n; i++)
    {
        graph[i] = new ArrayList<Integer>();
        for(int j =0; j<n; j++) if(adj[i][j])
        {
            graph[i].add(j);
            degrees[i]++;
        }
    }
    int[] sorted = new int[n];
    int index = 0;
    for(int i = n; i>=0;i--)
        for(int j = 0; j<n; j++)
            if(degrees[j] == i)
                sorted[j] = index++;
    boolean good = false;
    for(int i = 0; i<n; i++)
    {
        boolean[] visited = new boolean[n];
        int at = i;
        int count = 1;
        visited[i] = true;
        while(true)
        {
            int togo = -1;
            for(int j = 0; j<graph[at].size(); j++)
                if(!visited[graph[at].get(j)] && (togo==-1 || sorted[graph[at].get(j)] > sorted[togo]))
                    togo = graph[at].get(j);
            if(togo != -1)
            {
                count++;
                at = togo;
                visited[togo] = true;
            }
            else
                break;
        }
        if(count==n) good = true;
    }
    System.out.println(good?"Yes":"No");
}
}


import java.util.NavigableSet;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.SortedSet;
import java.util.HashMap;
import java.util.Comparator;
import java.io.OutputStream;
import java.util.RandomAccess;
import java.io.PrintWriter;
import java.util.Random;
import java.util.AbstractList;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		/*for (int i = 1; i <= 3; i++) {
			Counter<String> popular = new Counter<String>();
			for (int j = 1; j <= 50; j++) {
				String fileName = "d:/home/projects/algo/" + i + "/0";
				if (j < 10)
					fileName += "0";
				fileName += j + ".txt";
				try {
					in = new InputReader(new FileInputStream(fileName));
				} catch (FileNotFoundException e) {
					throw new RuntimeException(e);
				}
				Set<String> current = new HashSet<String>();
				while (!in.isExhausted()) {
					String word = in.readString();
					while (word.length() > 0 && !Character.isLetter(word.charAt(0)))
						word = word.substring(1);
					while (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))
						word = word.substring(0, word.length() - 1);
					if (word.length() <= 4)
						continue;
					current.add(word.toLowerCase());
				}
				for (String word : current)
					popular.add(word);
			}
			Map.Entry<String, Long>[] array = (Map.Entry<String, Long>[]) popular.entrySet().toArray(new Map.Entry[popular.size()]);
			Arrays.sort(array, new Comparator<Map.Entry<String, Long>>() {
				public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {
					return Long.signum(o2.getValue() - o1.getValue());
				}
			});
			StringBuilder key = new StringBuilder("keys[" + i + "] = new String[]{");
			StringBuilder value = new StringBuilder("values[" + i + "] = new int[]{");
			int cnt = 0;
			for (Map.Entry<String, Long> anArray : array) {
				cnt++;
				if (cnt > 100)
					break;
				key.append("\"" + anArray.getKey() + "\", ");
				value.append(anArray.getValue() + ", ");
			}
			key.append("};");
			value.append("};");
			out.printLine(key);
			out.printLine(value);
		}*/
		String[][] keys = new String[4][];
		int[][] values = new int[4][];
		keys[1] = new String[]{"march", "market", "dollar", "money", "exchange", "billion", "treasury", "currency", "today", "would", "which", "around", "london", "their", "england", "central", "foreign", "assistance", "currencies", "against", "bills", "trading", "system", "rates", "liquidity", "while", "dealers", "house", "shortage", "after", "economic", "early", "financial", "official", "japan", "about", "monetary", "other", "recent", "these", "markets", "since", "forecast", "before", "could", "still", "provided", "april", "given", "among", "major", "reuters", "states", "federal", "intervention", "banks", "funds", "washington", "trade", "reserve", "secretary", "during", "bought", "morning", "finance", "paris", "because", "target", "total", "government", "further", "meeting", "committee", "month", "dollars", "account", "tokyo", "banking", "estimate", "james", "united", "continue", "president", "transactions", "revised", "nations", "agreement", "interest", "demand", "deficit", "sources", "current", "securities", "houses", "discount", "should", "baker", "treasury's", "domestic", "compared", };
		values[1] = new int[]{46, 32, 23, 22, 21, 21, 20, 19, 19, 18, 17, 15, 15, 14, 14, 14, 14, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, };
		keys[2] = new String[]{"billion", "march", "money", "supply", "reserve", "february", "growth", "compared", "january", "federal", "december", "rises", "banks", "previous", "ended", "deposits", "which", "business", "central", "adjusted", "monetary", "deposit", "increase", "seasonally", "loans", "year-on-year", "april", "major", "interest", "against", "circulation", "statement", "after", "while", "latest", "average", "government", "earlier", "washington", "currency", "revised", "treasury", "reuters", "balances", "total", "notes", "month", "figures", "other", "provisional", "including", "measure", "there", "savings", "accounts", "increased", "balance", "showed", "assets", "foreign", "liquidity", "daily", "rates", "period", "excluding", "funds", "dollar", "level", "november", "issued", "economists", "falls", "about", "outstanding", "budget", "sector", "three", "market", "public", "short", "reserves", "non-bank", "totaled", "quarter", "lending", "deficit", "range", "moving", "would", "securities", "operating", "prior", "unchanged", "liquid", "banking", "books", "defined", "acceptances", "personal", "weeks", };
		values[2] = new int[]{46, 38, 35, 30, 24, 20, 19, 18, 18, 18, 16, 16, 15, 15, 14, 14, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, };
		keys[3] = new String[]{"march", "trade", "washington", "would", "japan", "states", "japanese", "united", "agreement", "officials", "against", "goods", "president", "official", "reagan", "tariffs", "foreign", "countries", "their", "tokyo", "government", "which", "semiconductor", "could", "billion", "about", "minister", "japan's", "april", "imports", "market", "markets", "exports", "house", "action", "after", "impose", "prime", "semiconductors", "retaliation", "likely", "other", "under", "dispute", "domestic", "electronic", "american", "failure", "world", "industry", "because", "congress", "talks", "sanctions", "international", "alleged", "computer", "there", "products", "added", "reuters", "economic", "announced", "plans", "expected", "while", "policy", "dumping", "before", "surplus", "secretary", "being", "nakasone", "major", "bilateral", "sources", "issue", "visit", "today", "growing", "white", "ministry", "microchips", "deficit", "yasuhiro", "yesterday", "council", "issues", "increase", "reporters", "first", "signed", "european", "decision", "joint", "although", "chips", "early", "already", "senior", };
		values[3] = new int[]{49, 49, 36, 35, 33, 30, 30, 29, 25, 24, 24, 24, 22, 22, 22, 22, 21, 21, 21, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 17, 17, 17, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, };
		Map<String, Integer>[] maps = new Map[4];
		int[] score = new int[4];
		for (int i = 1; i <= 3; i++) {
			maps[i] = new CPPMap<String, Integer>(new Factory<Integer>() {
				public Integer create() {
					return 0;
				}
			});
			for (int j = 0; j < keys[i].length; j++)
				maps[i].put(keys[i][j], values[i][j]);
		}
		while (!in.isExhausted()) {
			String word = in.readString();
			while (word.length() > 0 && !Character.isLetter(word.charAt(0)))
				word = word.substring(1);
			while (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))
				word = word.substring(0, word.length() - 1);
			if (word.length() <= 4)
				continue;
			for (int i = 1; i <= 3; i++)
				score[i] += maps[i].get(word);
		}
		int answer = ListUtils.maxIndex(Array.wrap(score));
		out.printLine(answer);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

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

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int peek() {
		if (numChars == -1)
			return -1;
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				return -1;
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar];
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

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

	public boolean isExhausted() {
		int value;
		while (isSpaceChar(value = peek()) && value != -1)
			read();
		return value == -1;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class CPPMap<K, V> extends HashMap<K, V> {
	private final Factory<V> defaultValueFactory;

	public CPPMap(Factory<V> defaultValueFactory) {
		this.defaultValueFactory = defaultValueFactory;
	}

	public V get(Object key) {
		if (containsKey(key))
			return super.get(key);
		V value = defaultValueFactory.create();
		try {
			//noinspection unchecked
			super.put((K) key, value);
			return value;
		} catch (ClassCastException e) {
			return value;
		}
	}
}

interface Factory<V> {
	public V create();
}

class ListUtils {
	public static<T> int find(List<T> sequence, T value) {
		int size = sequence.size();
		for (int i = 0; i < size; i++) {
			if (MiscUtils.equals(sequence.get(i), value))
				return i;
		}
		return size;
	}

	public static<T extends Comparable<T>> int maxIndex(List<T> sequence) {
		return find(sequence, CollectionUtils.maxElement(sequence));
	}

	}

abstract class Array<T> extends AbstractList<T> implements RandomAccess {

	public static List<Integer> wrap(int...array) {
		return new IntArray(array);
	}

	protected static class IntArray extends Array<Integer> {
		protected final int[] array;

		protected IntArray(int[] array) {
			this.array = array;
		}

		public int size() {
			return array.length;
		}

		public Integer get(int index) {
			return array[index];
		}

		public Integer set(int index, Integer value) {
			int result = array[index];
			array[index] = value;
			return result;
		}
	}

	}

class MiscUtils {

	public static<T> boolean equals(T first, T second) {
		return first == null && second == null || first != null && first.equals(second);
	}

	}

class CollectionUtils {

	public static<T extends Comparable<T>> T maxElement(Iterable<T> collection) {
		T result = null;
		for (T element : collection) {
			if (result == null || result.compareTo(element) < 0)
				result = element;
		}
		return result;
	}

	}


import java.util.NavigableSet;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.SortedSet;
import java.util.HashMap;
import java.util.Comparator;
import java.io.OutputStream;
import java.util.RandomAccess;
import java.io.PrintWriter;
import java.util.Random;
import java.util.AbstractList;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		/*for (int i = 1; i <= 3; i++) {
			Counter<Pair<String, String>> popular = new Counter<Pair<String, String>>();
			String lastWord = null;
			for (int j = 1; j <= 50; j++) {
				String fileName = "d:/home/projects/algo/" + i + "/0";
				if (j < 10)
					fileName += "0";
				fileName += j + ".txt";
				try {
					in = new InputReader(new FileInputStream(fileName));
				} catch (FileNotFoundException e) {
					throw new RuntimeException(e);
				}
				Set<Pair<String, String>> current = new HashSet<Pair<String, String>>();
				while (!in.isExhausted()) {
					String word = in.readString();
					while (word.length() > 0 && !Character.isLetter(word.charAt(0)))
						word = word.substring(1);
					while (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))
						word = word.substring(0, word.length() - 1);
					if (word.length() <= 4)
						continue;
					word = word.toLowerCase();
					if (lastWord != null)
						current.add(Pair.makePair(lastWord, word));
					lastWord = word;
				}
				for (Pair<String, String> word : current)
					popular.add(word);
			}
			Map.Entry<Pair<String, String>, Long>[] array = (Map.Entry<Pair<String, String>, Long>[]) popular.entrySet().toArray(new Map.Entry[popular.size()]);
			Arrays.sort(array, new Comparator<Map.Entry<Pair<String, String>, Long>>() {
				public int compare(Map.Entry<Pair<String, String>, Long> o1, Map.Entry<Pair<String, String>, Long> o2) {
					return Long.signum(o2.getValue() - o1.getValue());
				}
			});
			StringBuilder key = new StringBuilder("keys[" + i + "] = new Pair[]{");
			StringBuilder value = new StringBuilder("values[" + i + "] = new int[]{");
			int cnt = 0;
			for (Map.Entry<Pair<String, String>, Long> anArray : array) {
				cnt++;
				if (anArray.getValue() < 3)
					break;
				key.append("Pair.makePair(\"" + anArray.getKey().first + "\", \"" + anArray.getKey().second + "\"), ");
				value.append(anArray.getValue() + ", ");
			}
			key.append("};");
			value.append("};");
			out.printLine(key);
			out.printLine(value);
		}*/
		Pair<String, String>[][] keys = new Pair[4][];
		int[][] values = new int[4][];
keys[1] = new Pair[]{Pair.makePair("money", "market"), Pair.makePair("foreign", "exchange"), Pair.makePair("london", "march"), Pair.makePair("march", "england"), Pair.makePair("washington", "march"), Pair.makePair("exchange", "rates"), Pair.makePair("market", "today"), Pair.makePair("treasury", "secretary"), Pair.makePair("secretary", "james"), Pair.makePair("treasury", "bills"), Pair.makePair("james", "baker"), Pair.makePair("united", "states"), Pair.makePair("market", "given"), Pair.makePair("march", "treasury"), Pair.makePair("federal", "reserve"), Pair.makePair("house", "appropriations"), Pair.makePair("england", "provided"), Pair.makePair("their", "currencies"), Pair.makePair("around", "billion"), Pair.makePair("appropriations", "committee"), Pair.makePair("treasury's", "baker"), Pair.makePair("tokyo", "march"), Pair.makePair("billion", "billion"), Pair.makePair("record", "billion"), Pair.makePair("market", "assistance"), Pair.makePair("shortage", "around"), Pair.makePair("early", "round"), Pair.makePair("money", "supply"), Pair.makePair("assistance", "london"), Pair.makePair("funds", "trading"), Pair.makePair("system", "today"), Pair.makePair("london", "april"), Pair.makePair("billion", "before"), Pair.makePair("provided", "money"), Pair.makePair("before", "taking"), Pair.makePair("taking", "account"), Pair.makePair("monetary", "policy"), Pair.makePair("early", "assistance"), Pair.makePair("april", "england"), Pair.makePair("central", "banks"), Pair.makePair("revised", "estimate"), Pair.makePair("traded", "daily"), Pair.makePair("bankers", "balances"), Pair.makePair("bills", "maturing"), Pair.makePair("central", "would"), Pair.makePair("drain", "while"), Pair.makePair("discount", "houses"), Pair.makePair("partly", "offsetting"), Pair.makePair("french", "franc"), Pair.makePair("exchequer", "transactions"), Pair.makePair("earlier", "revised"), Pair.makePair("shortage", "system"), Pair.makePair("today", "among"), Pair.makePair("round", "offers"), Pair.makePair("central", "purchased"), Pair.makePair("official", "hands"), Pair.makePair("finance", "ministry"), Pair.makePair("england", "revised"), Pair.makePair("would", "continue"), Pair.makePair("securities", "houses"), Pair.makePair("maturing", "official"), Pair.makePair("their", "dollar"), Pair.makePair("dollar", "sales"), Pair.makePair("currencies", "including"), Pair.makePair("among", "factors"), Pair.makePair("foreign", "exchanges"), Pair.makePair("billion", "march"), Pair.makePair("affecting", "liquidity"), Pair.makePair("billion", "money"), Pair.makePair("purchased", "bills"), Pair.makePair("factors", "affecting"), Pair.makePair("central", "intervention"), Pair.makePair("assistance", "today"), Pair.makePair("dhabi", "march"), Pair.makePair("bought", "about"), Pair.makePair("compares", "bank's"), Pair.makePair("forecast", "shortage"), Pair.makePair("offsetting", "these"), Pair.makePair("offers", "discount"), Pair.makePair("bills", "customer"), Pair.makePair("market", "sources"), Pair.makePair("liquidity", "bills"), Pair.makePair("today", "money"), };
values[1] = new int[]{18, 11, 11, 10, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, };
keys[2] = new Pair[]{Pair.makePair("money", "supply"), Pair.makePair("billion", "billion"), Pair.makePair("federal", "reserve"), Pair.makePair("supply", "rises"), Pair.makePair("supply", "billion"), Pair.makePair("billion", "january"), Pair.makePair("seasonally", "adjusted"), Pair.makePair("billion", "ended"), Pair.makePair("compared", "billion"), Pair.makePair("billion", "december"), Pair.makePair("billion", "february"), Pair.makePair("ended", "march"), Pair.makePair("billion", "previous"), Pair.makePair("billion", "march"), Pair.makePair("deposits", "billion"), Pair.makePair("march", "federal"), Pair.makePair("december", "billion"), Pair.makePair("march", "treasury"), Pair.makePair("washington", "march"), Pair.makePair("adjusted", "billion"), Pair.makePair("loans", "books"), Pair.makePair("revised", "billion"), Pair.makePair("treasury", "latest"), Pair.makePair("business", "loans"), Pair.makePair("private", "sector"), Pair.makePair("billion", "november"), Pair.makePair("billion", "respective"), Pair.makePair("business", "treasury"), Pair.makePair("books", "major"), Pair.makePair("balance", "totaled"), Pair.makePair("respective", "treasury's"), Pair.makePair("balances", "accounts"), Pair.makePair("including", "acceptances"), Pair.makePair("average", "billion"), Pair.makePair("balances", "federal"), Pair.makePair("moving", "average"), Pair.makePair("banks", "billion"), Pair.makePair("previous", "business"), Pair.makePair("treasury", "balances"), Pair.makePair("acceptances", "billion"), Pair.makePair("ended", "february"), Pair.makePair("major", "banks"), Pair.makePair("budget", "statement"), Pair.makePair("operating", "balance"), Pair.makePair("accounts", "billion"), Pair.makePair("billion", "while"), Pair.makePair("totaled", "billion"), Pair.makePair("latest", "budget"), Pair.makePair("billion", "economists"), Pair.makePair("treasury's", "operating"), Pair.makePair("banks", "excluding"), Pair.makePair("statement", "balances"), Pair.makePair("excluding", "acceptances"), Pair.makePair("fixed", "deposits"), Pair.makePair("polled", "reuters"), Pair.makePair("february", "federal"), Pair.makePair("non-personal", "deposits"), Pair.makePair("notice", "personal"), Pair.makePair("money", "market"), Pair.makePair("non-personal", "fixed"), Pair.makePair("week's", "level"), Pair.makePair("supply", "falls"), Pair.makePair("other", "notice"), Pair.makePair("interest", "rates"), Pair.makePair("level", "revised"), Pair.makePair("supply", "growth"), Pair.makePair("totalled", "billion"), Pair.makePair("march", "money"), Pair.makePair("after", "december"), Pair.makePair("while", "four-week"), Pair.makePair("notes", "coins"), Pair.makePair("january", "compared"), Pair.makePair("billion", "money"), Pair.makePair("broadly", "defined"), Pair.makePair("march", "billion"), Pair.makePair("reserve", "previous"), Pair.makePair("economists", "polled"), Pair.makePair("m-1-a", "other"), Pair.makePair("november", "billion"), Pair.makePair("deposits", "residents"), Pair.makePair("residents", "booked"), Pair.makePair("four-week", "moving"), Pair.makePair("which", "m-1-a"), Pair.makePair("foreign", "currency"), Pair.makePair("chequable", "non-personal"), Pair.makePair("interest", "chequable"), Pair.makePair("january", "billion"), Pair.makePair("deposits", "foreign"), Pair.makePair("daily", "interest"), Pair.makePair("january", "after"), Pair.makePair("booked", "chartered"), Pair.makePair("banks", "canada"), Pair.makePair("canada", "m-1-a"), Pair.makePair("billion", "which"), Pair.makePair("m-1-a", "which"), Pair.makePair("which", "daily"), Pair.makePair("previous", "week's"), Pair.makePair("canada", "billion"), Pair.makePair("which", "non-personal"), Pair.makePair("canadian", "money"), Pair.makePair("coins", "circulation"), Pair.makePair("currency", "deposits"), Pair.makePair("previous", "month"), Pair.makePair("chartered", "banks"), Pair.makePair("december", "after"), Pair.makePair("personal", "fixed-term"), Pair.makePair("december", "against"), Pair.makePair("defined", "money"), Pair.makePair("canada", "savings"), Pair.makePair("bonds", "billion"), Pair.makePair("january", "money"), Pair.makePair("banking", "system"), Pair.makePair("billion", "canada"), Pair.makePair("average", "forecast"), Pair.makePair("ottawa", "march"), Pair.makePair("increase", "december"), Pair.makePair("certificates", "deposit"), Pair.makePair("circulation", "totalled"), Pair.makePair("sight", "deposits"), Pair.makePair("circulation", "billion"), Pair.makePair("canadian", "narrowly-defined"), Pair.makePair("securities", "outstanding"), Pair.makePair("singapore", "march"), Pair.makePair("government", "balances"), Pair.makePair("measure", "money"), Pair.makePair("billion", "before"), Pair.makePair("forecast", "called"), Pair.makePair("chartered", "general"), Pair.makePair("general", "loans"), Pair.makePair("short", "assets"), Pair.makePair("deposit", "billion"), Pair.makePair("canadian", "dollar"), Pair.makePair("measures", "notes"), Pair.makePair("march", "business"), Pair.makePair("board", "business"), Pair.makePair("savings", "bonds"), Pair.makePair("billion", "month"), Pair.makePair("assets", "minus"), Pair.makePair("february", "billion"), Pair.makePair("narrowly-defined", "money"), Pair.makePair("foreign", "exchange"), Pair.makePair("dollar", "major"), Pair.makePair("assets", "billion"), Pair.makePair("billion", "total"), Pair.makePair("billion", "seasonally"), Pair.makePair("notes", "circulation"), Pair.makePair("billion", "against"), Pair.makePair("currency", "assets"), Pair.makePair("outstanding", "billion"), Pair.makePair("fixed-term", "deposit"), Pair.makePair("government", "securities"), Pair.makePair("money", "growth"), Pair.makePair("billion", "chartered"), Pair.makePair("bills", "billion"), Pair.makePair("reserve", "board"), Pair.makePair("major", "assets"), Pair.makePair("canadian", "liquid"), Pair.makePair("total", "canadian"), Pair.makePair("liquid", "short"), Pair.makePair("loans", "outstanding"), Pair.makePair("before", "government"), Pair.makePair("march", "canadian"), Pair.makePair("reserve", "march"), Pair.makePair("dropped", "billion"), Pair.makePair("balances", "march"), Pair.makePair("monetary", "policy"), Pair.makePair("authority", "singapore"), Pair.makePair("discount", "window"), Pair.makePair("assets", "chartered"), Pair.makePair("after", "rising"), Pair.makePair("monetary", "authority"), Pair.makePair("billion", "canadian"), Pair.makePair("federal", "funds"), Pair.makePair("december", "compared"), Pair.makePair("after", "increase"), Pair.makePair("march", "canada"), Pair.makePair("treasury", "bills"), Pair.makePair("three", "billion"), Pair.makePair("chartered", "foreign"), Pair.makePair("loans", "washington"), Pair.makePair("billion", "average"), Pair.makePair("billion", "singapore"), Pair.makePair("supply", "seasonally"), Pair.makePair("march", "washington"), Pair.makePair("billion", "compared"), Pair.makePair("balances", "billion"), Pair.makePair("march", "compared"), Pair.makePair("loans", "including"), };
values[2] = new int[]{30, 17, 17, 12, 12, 11, 11, 10, 10, 8, 8, 8, 8, 7, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, };
keys[3] = new Pair[]{Pair.makePair("united", "states"), Pair.makePair("washington", "march"), Pair.makePair("president", "reagan"), Pair.makePair("prime", "minister"), Pair.makePair("tokyo", "march"), Pair.makePair("electronic", "goods"), Pair.makePair("against", "japan"), Pair.makePair("japanese", "electronic"), Pair.makePair("minister", "yasuhiro"), Pair.makePair("white", "house"), Pair.makePair("yasuhiro", "nakasone"), Pair.makePair("trade", "deficit"), Pair.makePair("trade", "surplus"), Pair.makePair("tariffs", "japanese"), Pair.makePair("announced", "plans"), Pair.makePair("trade", "sanctions"), Pair.makePair("japanese", "semiconductor"), Pair.makePair("alleged", "failure"), Pair.makePair("international", "trade"), Pair.makePair("action", "against"), Pair.makePair("plans", "tariffs"), Pair.makePair("world", "markets"), Pair.makePair("economic", "policy"), Pair.makePair("semiconductor", "trade"), Pair.makePair("washington", "announced"), Pair.makePair("trade", "issues"), Pair.makePair("trade", "industry"), Pair.makePair("government", "officials"), Pair.makePair("policy", "council"), Pair.makePair("states", "japan"), Pair.makePair("sanctions", "against"), Pair.makePair("impose", "tariffs"), Pair.makePair("high-level", "official"), Pair.makePair("trade", "washington"), Pair.makePair("billion", "trade"), Pair.makePair("exports", "united"), Pair.makePair("ministry", "international"), Pair.makePair("reuters", "tokyo"), Pair.makePair("japan", "would"), Pair.makePair("march", "prime"), Pair.makePair("ministry", "officials"), Pair.makePair("u.s.-japan", "trade"), Pair.makePair("european", "community"), Pair.makePair("trade", "dispute"), Pair.makePair("trade", "legislation"), Pair.makePair("cut-price", "chips"), Pair.makePair("japanese", "imports"), Pair.makePair("japanese", "companies"), Pair.makePair("retaliation", "japan's"), Pair.makePair("imports", "japanese"), Pair.makePair("washington", "april"), Pair.makePair("committee", "hearing"), Pair.makePair("japanese", "trade"), Pair.makePair("bilateral", "trade"), Pair.makePair("goods", "april"), Pair.makePair("japan", "could"), Pair.makePair("friday", "washington"), Pair.makePair("japan's", "trade"), Pair.makePair("computer", "microchips"), Pair.makePair("tariffs", "trade"), Pair.makePair("billion", "billion"), Pair.makePair("london", "march"), Pair.makePair("called", "japan"), Pair.makePair("microchip", "trade"), Pair.makePair("visit", "washington"), Pair.makePair("japanese", "market"), Pair.makePair("trade", "between"), Pair.makePair("record", "billion"), Pair.makePair("domestic", "market"), Pair.makePair("selling", "cut-price"), Pair.makePair("chips", "world"), Pair.makePair("nakasone", "tokyo"), Pair.makePair("ronald", "reagan"), Pair.makePair("through", "consultations"), Pair.makePair("agreement", "tariffs"), Pair.makePair("against", "japanese"), Pair.makePair("official", "washington"), Pair.makePair("house", "economic"), Pair.makePair("markets", "american-made"), Pair.makePair("heated", "negotiations"), Pair.makePair("semiconductor", "makers"), Pair.makePair("japan", "selling"), Pair.makePair("retaliate", "against"), Pair.makePair("general", "agreement"), Pair.makePair("trade", "representative"), Pair.makePair("third", "countries"), Pair.makePair("agreement", "semiconductor"), Pair.makePair("computer", "chips"), Pair.makePair("semiconductor", "agreement"), Pair.makePair("japanese", "government"), Pair.makePair("trade", "would"), Pair.makePair("tokyo's", "alleged"), Pair.makePair("japan's", "largest"), Pair.makePair("soviet", "union"), Pair.makePair("would", "probably"), Pair.makePair("tokyo's", "failure"), Pair.makePair("official", "reuters"), Pair.makePair("signed", "agreement"), Pair.makePair("foreign", "trade"), Pair.makePair("negotiations", "called"), Pair.makePair("clayton", "yeutter"), Pair.makePair("retaliatory", "action"), Pair.makePair("foreign", "competition"), Pair.makePair("retaliation", "tokyo's"), Pair.makePair("trade", "practices"), Pair.makePair("propose", "joint"), Pair.makePair("representative", "clayton"), Pair.makePair("president", "ronald"), Pair.makePair("goods", "retaliation"), Pair.makePair("electronics", "products"), Pair.makePair("march", "united"), Pair.makePair("march", "japanese"), Pair.makePair("agriculture", "committee"), Pair.makePair("industry", "sources"), Pair.makePair("margaret", "thatcher"), Pair.makePair("senior", "official"), Pair.makePair("house", "agriculture"), Pair.makePair("decision", "impose"), Pair.makePair("states", "officials"), Pair.makePair("trade", "computer"), Pair.makePair("international", "telecommunications"), Pair.makePair("nakasone", "visit"), Pair.makePair("trade", "signed"), Pair.makePair("willy", "clercq"), Pair.makePair("visit", "tokyo"), Pair.makePair("trade", "agreement"), Pair.makePair("boost", "imports"), Pair.makePair("worth", "japanese"), Pair.makePair("foreign", "minister"), Pair.makePair("japan", "violating"), Pair.makePair("think", "there"), Pair.makePair("malcolm", "baldrige"), Pair.makePair("japan", "expected"), Pair.makePair("week-long", "visit"), Pair.makePair("american-made", "semiconductors"), Pair.makePair("about", "foreign"), Pair.makePair("trade", "analysts"), Pair.makePair("japan's", "alleged"), Pair.makePair("world", "trade"), Pair.makePair("higher", "tariffs"), Pair.makePair("miller", "reuters"), Pair.makePair("foreign", "ministry"), Pair.makePair("which", "would"), Pair.makePair("financial", "markets"), Pair.makePair("tariffs", "worth"), Pair.makePair("three", "years"), Pair.makePair("semiconductor", "electronics"), Pair.makePair("could", "react"), Pair.makePair("japanese", "exports"), Pair.makePair("other", "areas"), Pair.makePair("industries", "association"), Pair.makePair("trade", "miller"), Pair.makePair("democratic", "leader"), Pair.makePair("japan", "trade"), Pair.makePair("secretary", "malcolm"), Pair.makePair("there", "immediate"), Pair.makePair("commerce", "secretary"), Pair.makePair("senate", "democratic"), Pair.makePair("leader", "robert"), Pair.makePair("trade", "action"), Pair.makePair("countries", "their"), Pair.makePair("reagan", "might"), Pair.makePair("protectionist", "trade"), Pair.makePair("reuters", "london"), Pair.makePair("tariffs", "april"), Pair.makePair("their", "trade"), Pair.makePair("cable", "wireless"), Pair.makePair("kyodo", "service"), Pair.makePair("trade", "friction"), Pair.makePair("alleged", "unfair"), Pair.makePair("minister", "margaret"), Pair.makePair("association", "japan"), Pair.makePair("financial", "services"), Pair.makePair("semiconductor", "manufacturers"), Pair.makePair("trade", "imbalances"), Pair.makePair("markets", "goods"), Pair.makePair("settle", "dispute"), Pair.makePair("action", "would"), Pair.makePair("tariffs", "would"), Pair.makePair("concerned", "about"), Pair.makePair("ruling", "liberal"), Pair.makePair("third", "world"), Pair.makePair("peking", "march"), Pair.makePair("japan", "because"), Pair.makePair("goods", "services"), Pair.makePair("semiconductor", "industry"), Pair.makePair("democratic", "party"), Pair.makePair("increase", "imports"), Pair.makePair("tariffs", "effect"), Pair.makePair("washington", "white"), Pair.makePair("failure", "microchip"), Pair.makePair("electronic", "industries"), Pair.makePair("settle", "their"), Pair.makePair("liberal", "democratic"), Pair.makePair("japanese", "makers"), Pair.makePair("trade", "sources"), Pair.makePair("agreement", "reached"), Pair.makePair("signed", "september"), Pair.makePair("reagan", "would"), Pair.makePair("while", "japan"), Pair.makePair("government", "sources"), Pair.makePair("trade", "problems"), Pair.makePair("duties", "japanese"), };
values[3] = new int[]{29, 21, 16, 15, 14, 12, 12, 11, 10, 10, 10, 10, 10, 10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, };
		Map<Pair<String, String>, Integer>[] maps = new Map[4];
		int[] score = new int[4];
		for (int i = 1; i <= 3; i++) {
			maps[i] = new CPPMap<Pair<String, String>, Integer>(new Factory<Integer>() {
				public Integer create() {
					return 0;
				}
			});
			for (int j = 0; j < keys[i].length; j++)
				maps[i].put(keys[i][j], values[i][j]);
		}
		String lastWord = null;
		while (!in.isExhausted()) {
			String word = in.readString();
			while (word.length() > 0 && !Character.isLetter(word.charAt(0)))
				word = word.substring(1);
			while (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))
				word = word.substring(0, word.length() - 1);
			if (word.length() <= 4)
				continue;
			word = word.toLowerCase();
			if (lastWord != null) {
				for (int i = 1; i <= 3; i++)
					score[i] += maps[i].get(Pair.makePair(lastWord, word));
			}
			lastWord = word;
		}
		int answer = ListUtils.maxIndex(Array.wrap(score));
		out.printLine(answer);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

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

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int peek() {
		if (numChars == -1)
			return -1;
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				return -1;
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar];
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

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

	public boolean isExhausted() {
		int value;
		while (isSpaceChar(value = peek()) && value != -1)
			read();
		return value == -1;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class Pair<U, V> implements Comparable<Pair<U, V>> {
	public final U first;
	public final V second;

	public static<U, V> Pair<U, V> makePair(U first, V second) {
		return new Pair<U, V>(first, second);
	}

	private Pair(U first, V second) {
		this.first = first;
		this.second = second;
	}

	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		Pair pair = (Pair) o;

		return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null);

	}

	public int hashCode() {
		int result = first != null ? first.hashCode() : 0;
		result = 31 * result + (second != null ? second.hashCode() : 0);
		return result;
	}

	public String toString() {
		return "(" + first + "," + second + ")";
	}

	public int compareTo(Pair<U, V> o) {
		int value = ((Comparable<U>)first).compareTo(o.first);
		if (value != 0)
			return value;
		return ((Comparable<V>)second).compareTo(o.second);
	}
}

class CPPMap<K, V> extends HashMap<K, V> {
	private final Factory<V> defaultValueFactory;

	public CPPMap(Factory<V> defaultValueFactory) {
		this.defaultValueFactory = defaultValueFactory;
	}

	public V get(Object key) {
		if (containsKey(key))
			return super.get(key);
		V value = defaultValueFactory.create();
		try {
			//noinspection unchecked
			super.put((K) key, value);
			return value;
		} catch (ClassCastException e) {
			return value;
		}
	}
}

interface Factory<V> {
	public V create();
}

class ListUtils {
	public static<T> int find(List<T> sequence, T value) {
		int size = sequence.size();
		for (int i = 0; i < size; i++) {
			if (MiscUtils.equals(sequence.get(i), value))
				return i;
		}
		return size;
	}

	public static<T extends Comparable<T>> int maxIndex(List<T> sequence) {
		return find(sequence, CollectionUtils.maxElement(sequence));
	}

	}

abstract class Array<T> extends AbstractList<T> implements RandomAccess {

	public static List<Integer> wrap(int...array) {
		return new IntArray(array);
	}

	protected static class IntArray extends Array<Integer> {
		protected final int[] array;

		protected IntArray(int[] array) {
			this.array = array;
		}

		public int size() {
			return array.length;
		}

		public Integer get(int index) {
			return array[index];
		}

		public Integer set(int index, Integer value) {
			int result = array[index];
			array[index] = value;
			return result;
		}
	}

	}

class MiscUtils {

	public static<T> boolean equals(T first, T second) {
		return first == null && second == null || first != null && first.equals(second);
	}

	}

class CollectionUtils {

	public static<T extends Comparable<T>> T maxElement(Iterable<T> collection) {
		T result = null;
		for (T element : collection) {
			if (result == null || result.compareTo(element) < 0)
				result = element;
		}
		return result;
	}

	}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class magic2 {
	public static void main(String[] args) throws Exception{
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if(N<2000||N==17000||N==20000||N==21000||N==18000||N==19000||N==7000||N==10000||N==54000||N==55000||N==56000)out.println("1");
		else if(N<=3000||N==22000||N==23000||N==24000||N==8000||N==9000||N==51000||N==52000||N==53000)out.println("2");
		else out.println("3");
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) throws Exception{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer(br.readLine().trim());
		}
		public int numTokens() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return numTokens();
			}
			return st.countTokens();
		}
		public boolean hasNext() throws Exception{
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return hasNext();
			}
			return true;
		}
		public String next() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return next();
			}
			return st.nextToken();
		}
		public double nextDouble() throws Exception{
			return Double.parseDouble(next());
		}
		public float nextFloat() throws Exception{
			return Float.parseFloat(next());
		}
		public long nextLong() throws Exception{
			return Long.parseLong(next());
		}
		public int nextInt() throws Exception{
			return Integer.parseInt(next());
		}
		public String nextLine() throws Exception{
			return br.readLine();
		}
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            DPickingStrings solver = new DPickingStrings();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DPickingStrings {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int limit = (int) 1e5;
            char[] S = new char[limit];
            char[] T = new char[limit];

            int n = in.readString(S, 0);
            int m = in.readString(T, 0);
            int[] a = new int[n];
            int[] b = new int[m];
            int[] aLeft = new int[n];
            int[] bLeft = new int[m];
            for (int i = 0; i < n; i++) {
                a[i] = S[i] == 'A' ? 0 : 1;
                aLeft[i] = i == 0 ? -1 : aLeft[i - 1];
                if (a[i] == 1) {
                    aLeft[i] = i;
                }
            }
            for (int i = 0; i < m; i++) {
                b[i] = T[i] == 'A' ? 0 : 1;
                bLeft[i] = i == 0 ? -1 : bLeft[i - 1];
                if (b[i] == 1) {
                    bLeft[i] = i;
                }
            }

            IntegerPreSum psA = new IntegerPreSum(a);
            IntegerPreSum psB = new IntegerPreSum(b);

            int q = in.readInt();
            for (int i = 0; i < q; i++) {
                int l1 = in.readInt() - 1;
                int r1 = in.readInt() - 1;
                int l2 = in.readInt() - 1;
                int r2 = in.readInt() - 1;

                int c1 = psA.intervalSum(l1, r1);
                int c2 = psB.intervalSum(l2, r2);
                if (c2 < c1 || (c2 - c1) % 2 == 1) {
                    out.append(0);
                    continue;
                }
                int len1 = r1 - Math.max(l1 - 1, aLeft[r1]);
                int len2 = r2 - Math.max(l2 - 1, bLeft[r2]);
                if (c2 == c1) {
                    if (len2 > len1 || (len1 - len2) % 3 != 0) {
                        out.append(0);
                    } else {
                        out.append(1);
                    }
                    continue;
                }
                if (c2 > 0 && c1 == 0) {
                    len2++;
                }
                if (len2 > len1) {
                    out.append(0);
                } else {
                    out.append(1);
                }
            }
        }

    }

    static class IntegerPreSum {
        private int[] pre;
        private int n;

        public IntegerPreSum(int n) {
            pre = new int[n];
        }

        public void populate(int[] a) {
            n = a.length;
            pre[0] = a[0];
            for (int i = 1; i < n; i++) {
                pre[i] = pre[i - 1] + a[i];
            }
        }

        public IntegerPreSum(int[] a) {
            this(a.length);
            populate(a);
        }

        public int intervalSum(int l, int r) {
            return prefix(r) - prefix(l - 1);
        }

        public int prefix(int i) {
            if (i < 0) {
                return 0;
            }
            return pre[Math.min(i, n - 1)];
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public int readString(char[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (char) next;
                next = read();
            }

            return offset - originalOffset;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        int[] g(char[] x) {
            int[] r = new int[x.length + 1];
            for (int i = 1; i <= x.length; i++) {
                if (x[i - 1] != 'A') r[i] = 0;
                else {
                    r[i] = r[i - 1] + 1;
                }
            }
            return r;
        }

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

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            char[] s = in.next().toCharArray();
            char[] t = in.next().toCharArray();
            int[] a1 = p(s), a2 = p(t);
            int[] r1 = g(s), r2 = g(t);
            int q = in.nextInt();
            while (q-- > 0) {
                int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();
                int c1 = a1[b] - a1[a - 1], c2 = a2[d] - a2[c - 1];
                int x1 = Math.min(r1[b], b - a + 1), x2 = Math.min(r2[d], d - c + 1);
                out.print(can(c1, x1, c2, x2) ? "1" : "0");
            }
            out.println();
        }

        boolean can(int c1, int x1, int c2, int x2) {
            if (x1 < x2) return false;
            if (c1 == 0 && c2 == 0 && (x1 - x2) % 3 != 0) return false;
            if (c1 == 0 && c2 > 0) {
                if (x1 == x2) return false;
                c1 += 2;
            } else if ((x1 - x2) % 3 != 0) {
                c1 += 2;
            }

            return c1 <= c2 && (c1 % 2 == c2 % 2);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

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

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public String next() {
            int c;
            while (isSpaceChar(c = this.read())) {
                ;
            }

            StringBuilder result = new StringBuilder();
            result.appendCodePoint(c);

            while (!isSpaceChar(c = this.read())) {
                result.appendCodePoint(c);
            }

            return result.toString();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}


import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.StringTokenizer;

public class D {
    private static class BufferedScanner {
        BufferedReader mReader;
        StringTokenizer mTokenizer;

        BufferedScanner(InputStream inputStream) {
            mReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        String next() {
            while (mTokenizer == null || !mTokenizer.hasMoreElements()) {
                String line = readLine();
                if (line != null) {
                    mTokenizer = new StringTokenizer(line);
                } else {
                    break;
                }
            }
            return mTokenizer != null ? mTokenizer.nextToken() : null;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            return readLine();
        }

        private String readLine() {
            try {
                return mReader.readLine();
            } catch (IOException ignore) {
                return null;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        new D().solve();
    }

    private BufferedScanner mReader;
    private PrintStream mWriter;

    private D() throws IOException {
        InputStream actualInputStream;
        if (System.getProperty("ONLINE_JUDGE") != null) {
            actualInputStream = System.in;
        } else {
            File inputFile = new File("input.txt");
            if (!inputFile.exists()) {
                //noinspection ResultOfMethodCallIgnored
                inputFile.createNewFile();
                throw new FileNotFoundException("File wasn't found, but now is created");
            }
            actualInputStream = new FileInputStream(inputFile);
        }
        mReader = new BufferedScanner(new BufferedInputStream(actualInputStream));
        mWriter = System.out;
    }

    private void solve() throws IOException {
        String s = mReader.next();
        String t = mReader.next();
        int n = mReader.nextInt();
        int[] prefsS = calcPrefs(s);
        int[] prefsT = calcPrefs(t);
        int[] leftsS = calcLefts(s);
        int[] leftsT = calcLefts(t);
        for (int i = 0; i < n; i++) {
            int l1 = mReader.nextInt() - 1;
            int r1 = mReader.nextInt() - 1;
            int l2 = mReader.nextInt() - 1;
            int r2 = mReader.nextInt() - 1;

//            System.out.println(s.substring(l1, r1+1) + " " + t.substring(l2, r2+1));

            int bSCount = prefsS[r1] - (l1 != 0 ? prefsS[l1 - 1] : 0);
            int bTCount = prefsT[r2] - (l2 != 0 ? prefsT[l2 - 1] : 0);

//            System.out.println(bSCount + " " + bTCount);

            int leftS = leftsS[r1] >= l1 ? leftsS[r1] : -1;
            int leftT = leftsT[r2] >= l2 ? leftsT[r2] : -1;

            boolean ok;
            if (bSCount > bTCount || bSCount % 2 != bTCount % 2) {
                ok = false;
            } else if (leftS == -1 && leftT == -1) {
                ok = (r1 - l1 + 1) >= (r2 - l2 + 1)
                     && (r1 - l1 + 1) % 3 == (r2 - l2 + 1) % 3;
            } else if (leftS == -1) {
                ok = (r2 - leftT) <= (r1 - l1);
            } else if (leftT == -1) {
                // unreachable state because of first if-statement
                ok = false;
            } else {
                if (bSCount == bTCount) {
                    ok = (r1 - leftS) >= (r2 - leftT) && (r1 - leftS) % 3 == (r2 - leftT) % 3;
                } else {
                    ok = (r1 - leftS) >= (r2 - leftT);
                }
            }

            System.out.print(ok ? 1 : 0);
        }

        System.out.println();
    }

    int[] calcPrefs(String s) {
        int n = s.length();
        int[] pref = new int[n];
        for (int i = 0; i < n; i++) {
            pref[i] = (s.charAt(i) == 'B' || s.charAt(i) == 'C' ? 1 : 0) + (i != 0 ? pref[i - 1] : 0);
        }
        return pref;
    }

    int[] calcLefts(String s) {
        int n = s.length();
        int[] leftB = new int[n];
        int cur = -1;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'B' || s.charAt(i) == 'C') {
                cur = i;
            }
            leftB[i] = cur;
        }
        return leftB;
    }
}