#include <bits/stdc++.h>
using namespace std;
const int MN = 1100;
int a[MN][60];
int pt[MN];
map<string, int> m;
string st[MN];
int ef, n;
int b[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int f(int aa, int bb) {
  if (pt[aa] != pt[bb]) {
    return pt[aa] > pt[bb];
  } else {
    for (int i = 0; i < 60; i++) {
      if (a[aa][i] != a[bb][i]) {
        return a[aa][i] > a[bb][i];
      }
    }
    return 0;
  }
}
int f2(int aa, int bb) {
  if (a[aa][0] != a[bb][0]) {
    return a[aa][0] > a[bb][0];
  } else {
    return f(aa, bb);
  }
}
int main() {
  int t;
  cin >> t;
  for (int ii = 0; ii < t; ii++) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (m.find(s) == m.end()) {
        m[s] = ef++;
        st[ef - 1] = s;
      }
      a[m[s]][i]++;
      if (i <= 9) pt[m[s]] += b[i];
    }
  }
  int r[MN];
  for (int i = 0; i < m.size(); i++) {
    r[i] = i;
  }
  sort(r, r + m.size(), f);
  cout << st[r[0]] << endl;
  sort(r, r + m.size(), f2);
  cout << st[r[0]] << endl;
}
