#include <bits/stdc++.h>
using namespace std;
struct team {
  string name;
  int score;
  int rank[51];
};
map<string, team> mp;
int scores[51] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
bool Less1(const team &a, const team &b) {
  if (a.score != b.score) return a.score > b.score;
  for (int i = 0; i < 51; i++)
    if (a.rank[i] != b.rank[i]) return a.rank[i] > b.rank[i];
  return false;
}
bool Less2(const team &a, const team &b) {
  if (a.rank[0] != b.rank[0]) return a.rank[0] > b.rank[0];
  if (a.score != b.score) return a.score > b.score;
  for (int i = 0; i < 51; i++)
    if (a.rank[i] != b.rank[i]) return a.rank[i] > b.rank[i];
  return false;
}
int main() {
  int t, n;
  string s;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> s;
      if (!mp.count(s)) {
        team T;
        mp[s] = T;
      }
      team &T = mp[s];
      T.name = s;
      T.score += scores[i];
      T.rank[i]++;
    }
  }
  vector<team> T;
  map<string, team>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) T.push_back(it->second);
  sort(T.begin(), T.end(), Less1);
  cout << T[0].name << endl;
  sort(T.begin(), T.end(), Less2);
  cout << T[0].name << endl;
  return 0;
}
