const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
rl.on("line", function (line) {
  console.log(compare(line));
});
function compare(line) {
  const tokens = line.split("-");
  const cards = "3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER";
  if (line.includes("joker JOKER")) return "joker JOKER";
  let one = tokens[0].split(" "),
    two = tokens[1].split(" ");
  if (one.length === two.length) {
    return cards.indexOf(one[0]) > cards.indexOf(two[0]) ? tokens[0] : tokens[1];
  } else if (one.length === 4) {
    return tokens[0];
  } else if (two.length === 4) {
    return tokens[1];
  } else {
    return "ERROR";
  }
}