#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  map<string, array<int, 51> > s;
  int table[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    for (int j = 0; j < n; j++) {
      string d;
      cin >> d;
      if (j < 10) {
        s[d][0] += table[j];
      }
      s[d][j + 1]++;
    }
  }
  vector<pair<array<int, 51>, string> > ps;
  for (auto item : s) {
    ps.push_back(pair<array<int, 51>, string>(item.second, item.first));
  }
  sort(ps.rbegin(), ps.rend());
  cout << ps[0].second << endl;
  for (int i = 0; i < ps.size(); i++) {
    swap(ps[i].first[0], ps[i].first[1]);
  }
  sort(ps.rbegin(), ps.rend());
  cout << ps[0].second << endl;
  return 0;
}
