#include <bits/stdc++.h>
using namespace std;
const int A[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> mm;
string w[2505];
int pt[2505], win[2505][55];
bool fs1(int x, int y) {
  if (pt[x] != pt[y]) return pt[x] > pt[y];
  for (int i = 0;; i++)
    if (win[x][i] != win[y][i]) return win[x][i] > win[y][i];
  return false;
}
bool fs2(int x, int y) {
  if (win[x][0] != win[y][0]) return win[x][0] > win[y][0];
  return fs1(x, y);
}
int main() {
  int t, m = 0;
  char namechar[100];
  scanf("%d", &t);
  while (t--) {
    int n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%s", namechar);
      string the_name = string(namechar);
      if (mm.count(the_name) == 0) {
        mm[the_name] = m;
        m = m + 1;
        w[mm[the_name]] = the_name;
      }
      if (i < 10) {
        pt[mm[the_name]] += A[i];
      }
      ++win[mm[the_name]][i];
    }
  }
  int mi = 0, mj = 0, i;
  for (i = 1; i < (int)mm.size(); i++) {
    if (fs1(i, mi)) mi = i;
    if (fs2(i, mj)) mj = i;
  }
  cout << w[mi].c_str() << endl << w[mj].c_str();
  return 0;
}
