#include <bits/stdc++.h>
using namespace std;
struct P {
  string name;
  int rank[60], score;
} f[1010];
map<string, int> names;
const int point[60] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
bool cmp1(P a, P b) {
  if (a.score == b.score)
    for (int i = 1; i <= 50; i++)
      if (a.rank[i] != b.rank[i]) return a.rank[i] > b.rank[i];
  return a.score > b.score;
}
bool cmp2(P a, P b) {
  if (a.rank[1] == b.rank[1]) {
    if (a.score != b.score) return a.score > b.score;
    for (int i = 2; i <= 50; i++)
      if (a.rank[i] != b.rank[i]) return a.rank[i] > b.rank[i];
  }
  return a.rank[1] > b.rank[1];
}
int main() {
  int n, m, tot = 0;
  string s;
  cin >> n;
  while (n--) {
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> s;
      if (!names[s]) names[s] = ++tot, f[tot].name = s;
      f[names[s]].rank[i]++;
      f[names[s]].score += point[i];
    }
  }
  sort(f + 1, f + tot + 1, cmp1);
  cout << f[1].name << endl;
  sort(f + 1, f + tot + 1, cmp2);
  cout << f[1].name << endl;
  return 0;
}
