#include <bits/stdc++.h>
using namespace std;
map<string, int> name;
map<int, string> num;
struct s {
  int num;
  int score;
  int vis[60];
} sn[60];
bool cmp1(s a, s b) {
  if (a.score == b.score) {
    for (int i = 1; i <= 50; i++)
      if (a.vis[i] == b.vis[i])
        continue;
      else
        return a.vis[i] > b.vis[i];
  } else {
    return a.score > b.score;
  }
}
bool cmp2(s a, s b) {
  if (a.vis[1] == b.vis[1]) {
    if (a.score == b.score) {
      for (int i = 2; i <= 50; i++)
        if (a.vis[i] == b.vis[i])
          continue;
        else
          return a.vis[i] > b.vis[i];
    } else
      return a.score > b.score;
  } else
    return a.vis[1] > b.vis[1];
}
int main() {
  int n, m, i, j, cnt = 1;
  string a;
  while (~scanf("%d", &n)) {
    for (i = 0; i < n; i++) {
      scanf("%d", &m);
      for (j = 1; j <= m; j++) {
        cin >> a;
        if (name[a] == 0) {
          name[a] = cnt;
          num[cnt] = a;
          sn[name[a]].num = cnt;
          cnt++;
        }
        if (j == 1)
          sn[name[a]].score += 25, sn[name[a]].vis[j]++;
        else if (j == 2)
          sn[name[a]].score += 18, sn[name[a]].vis[j]++;
        else if (j == 3)
          sn[name[a]].score += 15, sn[name[a]].vis[j]++;
        else if (j == 4)
          sn[name[a]].score += 12, sn[name[a]].vis[j]++;
        else if (j == 5)
          sn[name[a]].score += 10, sn[name[a]].vis[j]++;
        else if (j == 6)
          sn[name[a]].score += 8, sn[name[a]].vis[j]++;
        else if (j == 7)
          sn[name[a]].score += 6, sn[name[a]].vis[j]++;
        else if (j == 8)
          sn[name[a]].score += 4, sn[name[a]].vis[j]++;
        else if (j == 9)
          sn[name[a]].score += 2, sn[name[a]].vis[j]++;
        else if (j == 10)
          sn[name[a]].score += 1, sn[name[a]].vis[j]++;
        else
          sn[name[a]].score += 0, sn[name[a]].vis[j]++;
      }
    }
    sort(sn, sn + cnt, cmp1);
    cout << num[sn[0].num] << endl;
    sort(sn, sn + cnt, cmp2);
    cout << num[sn[0].num] << endl;
    cnt = 1;
    name.clear();
    num.clear();
  }
}
