#include <bits/stdc++.h>
using namespace std;
int p[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int t, n;
int v;
string s[1010];
map<string, int> tr;
int pts[1010];
vector<vector<int> > cnt(1010, vector<int>(60));
int main() {
  int i, u, um;
  string str;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> str;
      if (!tr.count(str)) {
        s[v] = str;
        tr[str] = v;
        v++;
      }
      u = tr[str];
      if (i < 10) pts[u] += p[i];
      cnt[u][i]++;
    }
  }
  um = 0;
  for (u = 0; u < v; u++) {
    if (pts[um] < pts[u] or pts[um] == pts[u] and cnt[um] < cnt[u]) um = u;
  }
  cout << s[um] << endl;
  um = 0;
  for (u = 0; u < v; u++) {
    if (cnt[um][0] < cnt[u][0] or
        cnt[um][0] == cnt[u][0] and
            (pts[um] < pts[u] or pts[um] == pts[u] and cnt[um] < cnt[u]))
      um = u;
  }
  cout << s[um] << endl;
  return 0;
}
