#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const double pi = 3.14159265358979323;
const double eps = 1e-8;
const int sum[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1, 0};
int n, m, k;
struct Tnode {
  int cnt[110], pt;
  string name;
} a[210];
map<string, int> id;
bool cmp1(Tnode a1, Tnode b1) {
  if (a1.pt != b1.pt)
    return a1.pt > b1.pt;
  else {
    for (int i = (0); i < (50); i++)
      if (a1.cnt[i] != b1.cnt[i]) return a1.cnt[i] > b1.cnt[i];
  }
  return true;
}
bool cmp2(Tnode a1, Tnode b1) {
  if (a1.cnt[0] != b1.cnt[0])
    return a1.cnt[0] > b1.cnt[0];
  else {
    if (a1.pt != b1.pt)
      return a1.pt > b1.pt;
    else {
      for (int i = (1); i < (50); i++)
        if (a1.cnt[i] != b1.cnt[i]) return a1.cnt[i] > b1.cnt[i];
    }
  }
  return true;
}
int main() {
  int T;
  string s;
  cin >> T;
  m = 0;
  k = T;
  for (int i = (0); i < (110); i++) {
    memset(a[i].cnt, 0, sizeof(a[i].cnt));
    a[i].pt = 0;
    a[i].name.clear();
  }
  id.clear();
  while (T--) {
    cin >> n;
    for (int i = (0); i < (n); i++) {
      cin >> s;
      if (id.find(s) == id.end()) id[s] = m++;
      int pid = id[s];
      a[pid].name = s;
      if (i < 10) a[pid].pt += sum[i];
      a[pid].cnt[i]++;
    }
  }
  sort(a, a + m, cmp1);
  cout << a[0].name << endl;
  sort(a, a + m, cmp2);
  cout << a[0].name << endl;
  return 0;
}
