#include <bits/stdc++.h>
using namespace std;
struct Team {
  string name;
  int score;
  int winTimes[50];
};
bool less1(const Team& a, const Team& b) {
  bool ans = false;
  if (a.score != b.score)
    ans = a.score > b.score;
  else {
    for (int i = 0; i < 50; i++) {
      if (a.winTimes[i] != b.winTimes[i]) {
        ans = a.winTimes[i] > b.winTimes[i];
        break;
      }
    }
  }
  return ans;
}
bool less2(const Team& a, const Team& b) {
  bool ans = false;
  if (a.winTimes[0] != b.winTimes[0])
    ans = a.winTimes[0] > b.winTimes[0];
  else if (a.score != b.score)
    ans = a.score > b.score;
  else {
    for (int i = 1; i < 50; i++) {
      if (a.winTimes[i] != b.winTimes[i]) {
        ans = a.winTimes[i] > b.winTimes[i];
        break;
      }
    }
  }
  return ans;
}
int scores[50] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int main() {
  map<string, Team> mpTeam;
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    for (int j = 0; j < n; j++) {
      string s;
      cin >> s;
      if (!mpTeam.count(s)) {
        mpTeam[s].name = s;
        mpTeam[s].score = scores[j];
        mpTeam[s].winTimes[j] = 1;
      } else {
        mpTeam[s].score += scores[j];
        mpTeam[s].winTimes[j]++;
      }
    }
  }
  vector<Team> teams;
  map<string, Team>::iterator it;
  for (it = mpTeam.begin(); it != mpTeam.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;
}
