import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            String[] split = line.split("-");
            String[] arr1 = split[0].split(" ");
            String[] arr2 = split[1].split(" ");
            Arrays.sort(arr1);
            Arrays.sort(arr2);
            String[] sortArr = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER"};
            Map<String, Integer> map = new HashMap<>();
            for (int i = 0; i < sortArr.length; i++) {
                map.put(sortArr[i], i);
            }
            int length1 = arr1.length;
            int length2 = arr2.length;
            if (length1 == length2) {
                if (map.get(arr1[0]) > map.get(arr2[0])) {
                    System.out.println(split[0]);
                } else {
                    System.out.println(split[1]);
                }
            } else if (length1 == 2 && Arrays.toString(arr1).contains("joker")) {
                System.out.println(split[0]);
            } else if (length2 == 2 && Arrays.toString(arr2).contains("joker")) {
                System.out.println(split[1]);
            } else if (length1 == 4) {
                System.out.println(split[0]);
            } else if (length2 == 4) {
                System.out.println(split[1]);
            } else {
                System.out.println("ERROR");
            }

        }
    }
}