#include <bits/stdc++.h>
using namespace std;
int get_point(int N) {
  int score[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  if (N > 10) return 0;
  return score[N - 1];
}
int main() {
  int T;
  map<string, int> n_map;
  map<string, string> n_win;
  cin >> T;
  for (int i = 0; i < (T); ++i) {
    int N;
    cin >> N;
    for (int j = 0; j < (N); ++j) {
      string t_s;
      cin >> t_s;
      n_map[t_s] += get_point(j + 1);
      if (n_win[t_s] == "")
        n_win[t_s] = "0000000000000000000000000000000000000000000000000000";
      n_win[t_s][j] += 1;
    }
  }
  map<string, int>::iterator it;
  int n_max1 = 0, n_max2 = 0;
  string n_ret1 = "", n_ret2 = "";
  n_win[""] = "0000000000000000000000000000000000000000000000000000";
  for (it = n_map.begin(); it != n_map.end(); it++) {
    if (n_max1 < (*it).second) {
      n_ret1 = (*it).first;
      n_max1 = (*it).second;
    }
    if (n_max1 == (*it).second && n_win[n_ret1] < n_win[(*it).first]) {
      n_ret1 = (*it).first;
      n_max1 = (*it).second;
    }
    if (n_win[n_ret2][0] < n_win[(*it).first][0]) {
      n_ret2 = (*it).first;
      n_max2 = (*it).second;
    }
    if (n_win[n_ret2][0] == n_win[(*it).first][0] && n_max2 < (*it).second) {
      n_ret2 = (*it).first;
      n_max2 = (*it).second;
    }
    if (n_win[n_ret2][0] == n_win[(*it).first][0] && n_max2 == (*it).second) {
      if (n_win[n_ret2] < n_win[(*it).first]) {
        n_ret2 = (*it).first;
        n_max2 = (*it).second;
      }
    }
  }
  cout << n_ret1 << endl;
  cout << n_ret2 << endl;
  return 0;
}
