#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
const int inf = 0x3f3f3f3f;
char sc[maxn] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct node {
  int p, w[maxn];
} z, n;
map<string, node> r;
bool cmp1(node a, node b) {
  if (a.p != b.p) return a.p > b.p;
  for (int i = 0; i < 55; i++) {
    if (a.w[i] != b.w[i]) return a.w[i] > b.w[i];
  }
  return false;
}
bool cmp2(node a, node b) {
  if (a.w[0] != b.w[0]) return a.w[0] > b.w[0];
  return cmp1(a, b);
}
string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> s;
      int cnt = 0;
      if (i < 10) r[s].p += sc[i];
      r[s].w[i]++;
    }
  }
  string ans1 = r.begin()->first, ans2 = r.begin()->first;
  for (auto it : r) {
    if (cmp1(it.second, r[ans1])) ans1 = it.first;
    if (cmp2(it.second, r[ans2])) ans2 = it.first;
  }
  cout << ans1 << "\n";
  cout << ans2 << "\n";
  return 0;
}
