#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define lowbit(x) = ((x)& - (x))
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
using namespace std;
typedef long long ll;
ll fastPow(ll a, ll n, ll mod){
ll ans = 1;
a %= mod;
while(n) {
if(n & 1) ans = (ans*a) % mod;
a = (a*a) % mod;
n >>= 1;
}
return ans;
}
int gcd(int a, int b) {
while (b != 0) {
int tmp = a;
a = b;
b = tmp % b;
}
return a;
}
/*int sum(int x){
int ans = 0;
while(x>0){
ans+=tree[x];
x-=lowbit(x);
}
return ans;
}
void update(int x,int d){
while(x<=//N){
tree[x]+=d;
x+=lowbit(x)
}
}*/
const int N = 8;
string s[9];
int a[9];
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
rep(i,1,N)cin>>s[i]>>a[i];
for(int i = 1;i<=8;i+=2){
if(a[i]<a[i+1]){
s[i] = s[i+1];
a[i] = a[i+1];
}
}
for(int i = 1;i<=8;i+=4){
if(a[i]<a[i+2]){
s[i] = s[i+2];
a[i] = a[i+2];
}
}
if(a[1]>a[5])cout<<s[1]<<" beats "<<s[5];
else cout<<s[5]<<" beats "<<s[1];
return 0;
}