#include <bits/stdc++.h>
using namespace std;
int n, m, cnt = 0, a[1005];
int aw[55] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, vector<int> > ww;
map<string, int> ps;
struct id {
  string n;
  id(string n) : n(n) {}
};
bool rule1(const id& l, const id& r) {
  if (ps[l.n] != ps[r.n])
    return ps[l.n] > ps[r.n];
  else
    return ww[l.n] > ww[r.n];
}
bool rule2(const id& l, const id& r) {
  if (ww[l.n][0] != ww[r.n][0])
    return ww[l.n][0] > ww[r.n][0];
  else if (ps[l.n] != ps[r.n])
    return ps[l.n] > ps[r.n];
  return ww[l.n] > ww[r.n];
}
int main() {
  int t;
  cin >> t;
  vector<id> dris;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    for (int j = 0; j < n; j++) {
      string s;
      cin >> s;
      if (ps.find(s) == ps.end()) {
        ps[s] = 0;
        ww[s] = vector<int>(100, 0);
        dris.push_back(id(s));
      }
      ww[s][j]++;
      ps[s] += aw[j];
    }
  }
  sort(dris.begin(), dris.end(), rule1);
  cout << dris[0].n << endl;
  sort(dris.begin(), dris.end(), rule2);
  cout << dris[0].n << endl;
  return 0;
}
