#include <bits/stdc++.h>
using namespace std;
struct racer {
  int pos[51];
  int score;
};
map<string, racer> m;
int t, n, sc[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}, mxn = 0;
string s;
bool cmp1(racer a, racer b) {
  if (a.score != b.score) return a.score > b.score;
  for (int i = 0; i < mxn; i++) {
    if (a.pos[i] != b.pos[i]) return a.pos[i] > b.pos[i];
  }
  return false;
}
bool cmp2(racer a, racer b) {
  if (a.pos[0] != b.pos[0]) return a.pos[0] > b.pos[0];
  return cmp1(a, b);
}
int main() {
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    mxn = max(mxn, n);
    for (int j = 0; j < n; j++) {
      cin >> s;
      if (j < 10) m[s].score += sc[j];
      m[s].pos[j]++;
    }
  }
  string max1 = m.begin()->first, max2 = m.begin()->first;
  for (map<string, racer>::iterator it = m.begin(); it != m.end(); it++) {
    if (cmp1(it->second, m[max1])) max1 = it->first;
    if (cmp2(it->second, m[max2])) max2 = it->first;
  }
  cout << max1 << endl << max2;
  return 0;
}
