#include<stdio.h>
#include<ctype.h>
typedef struct typev_ {
int type;
int val;
}typev;
int toint(char* s) {
int i = 0, val;
while (s[i])i++;
if (i > 1)val = i == 2 ? 10 : s[0] == 'j' ? 16 : 17;
else {
if (isdigit(s[0])) {
val = s[0] - '0';
if (val == 2)val = 15;
}
else {
val = s[0] == 'J' ? 11 :
s[0] == 'Q' ? 12 :
s[0] == 'K' ? 13 : 14;
}
}
return val;
}
typev totv(char ss[6][6]) {
int len = 0;
typev res;
while (ss[len][0])len++;
res.type = len;
res.val = toint(ss[0]);
if (res.type == 2 && res.val > 15) {
res.type = 4;
res.val = 16;
}
return res;
}
int main() {
char input[32];
char ss1[6][6], ss2[6][6];
while (fgets(input, 32, stdin)) {
int i = 0, len1, len2;
while (input[i] != '\n')i++;
input[i] = 0;
i=0;
while (input[i] != '-')i++;
len2 = sscanf(input + i + 1, "%s%s%s%s%s", ss2[0], ss2[1], ss2[2], ss2[3], ss2[4]);
ss2[len2][0] = 0;
input[i] = 0;
len1 = sscanf(input, "%s%s%s%s%s", ss1[0], ss1[1], ss1[2], ss1[3], ss1[4]);
ss1[len1][0] = 0;
typev poke1 = totv(ss1), poke2 = totv(ss2);
if (poke1.type == poke2.type)
printf("%s\n", poke1.val > poke2.val ? input : input + i + 1);
else if (poke1.type == 4 || poke2.type == 4)
printf("%s\n", poke1.type == 4 ? input : input + i + 1);
else
printf("ERROR\n");
}
}