#include <bits/stdc++.h>
using namespace std;
int points[50] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0,
                  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
map<string, vector<int>> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  string name;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      cin >> name;
      if (!mp.count(name)) mp[name] = vector<int>(51);
      mp[name][0] += points[i];
      ++mp[name][i + 1];
    }
  }
  for (auto &i : mp)
    if (mp[name] < i.second) name = i.first;
  cout << name << endl;
  for (auto &i : mp) swap(i.second[0], i.second[1]);
  for (auto &i : mp)
    if (mp[name] < i.second) name = i.first;
  cout << name << endl;
  return 0;
}
