#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  int point[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  while (cin >> t) {
    int size = 0;
    map<string, int> mp;
    vector<pair<vector<int>, string> > vi;
    vector<string> vs;
    for (int i = 0; i < t; i++) {
      int n;
      cin >> n;
      for (int j = 0; j < n; j++) {
        string s;
        cin >> s;
        if (!mp.count(s)) {
          mp[s] = size;
          size++;
          vi.push_back(make_pair(vector<int>(51, 0), s));
        }
        if (j < 10) vi[mp[s]].first[0] += point[j];
        vi[mp[s]].first[j + 1]++;
      }
    }
    sort(vi.begin(), vi.end());
    cout << vi.back().second << endl;
    for (int i = 0; i < vi.size(); i++) swap(vi[i].first[0], vi[i].first[1]);
    sort(vi.begin(), vi.end());
    cout << vi.back().second << endl;
  }
}
