#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, num[100] = {-1, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> mapp;
struct aa {
  int score;
  string name;
  int rr[100];
} a[1005];
bool cmp(aa x, aa y) {
  if (x.score != y.score) return x.score > y.score;
  for (i = 1; i < 50; i++) {
    if (x.rr[i] == y.rr[i]) continue;
    return x.rr[i] > y.rr[i];
  }
}
bool cmpp(aa x, aa y) {
  if (x.rr[1] != y.rr[1]) return x.rr[1] > y.rr[1];
  if (x.score != y.score) return x.score > y.score;
  for (i = 2; i < 50; i++) {
    if (x.rr[i] == y.rr[i]) continue;
    return x.rr[i] > y.rr[i];
  }
}
int main() {
  scanf("%d", &n);
  string s;
  int c = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &m);
    for (j = 1; j <= m; j++) {
      cin >> s;
      if (!mapp.count(s)) mapp[s] = c++;
      a[mapp[s]].score += num[j];
      a[mapp[s]].name = s;
      a[mapp[s]].rr[j]++;
    }
  }
  sort(a, a + c, cmp);
  cout << a[0].name << endl;
  sort(a, a + c, cmpp);
  cout << a[0].name << endl;
}
