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