#include <bits/stdc++.h>
using namespace std;
int p[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct Player {
  string name;
  int points, place[51];
  Player() { points = 0, memset(place, 0, sizeof place); }
};
bool greater1(Player a, Player b) {
  if (a.points != b.points) return a.points > b.points;
  for (int i = 0; i < 51; i++)
    if (a.place[i] != b.place[i]) return a.place[i] > b.place[i];
}
bool greater2(Player a, Player b) {
  if (a.place[0] != b.place[0]) return a.place[0] > b.place[0];
  if (a.points != b.points) return a.points > b.points;
  for (int i = 1; i < 51; i++)
    if (a.place[i] != b.place[i]) return a.place[i] > b.place[i];
}
map<string, Player> m;
int main() {
  int t, n;
  string s;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> s;
      Player &temp = m[s];
      if (i < 10) temp.points += p[i];
      temp.place[i]++;
      temp.name = s;
    }
  }
  Player res1 = m.begin()->second, res2 = m.begin()->second;
  for (map<string, Player>::iterator it = m.begin(); it != m.end(); it++) {
    if (greater1(it->second, res1)) res1 = it->second;
    if (greater2(it->second, res2)) res2 = it->second;
  }
  cout << res1.name << endl << res2.name;
  return 0;
}
