#include <bits/stdc++.h>
using namespace std;
int A[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> id;
string w[2505];
int pt[2505], win[2505][55];
bool cmp1(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 cmp2(int x, int y) {
  if (win[x][0] != win[y][0]) return win[x][0] > win[y][0];
  return cmp1(x, y);
}
int main(void) {
  int t, m = 0;
  char z[100];
  scanf("%d", &t);
  while (t--) {
    int n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%s", z);
      string str = string(z);
      if (id.count(str) == 0) {
        id[str] = m++;
        w[id[str]] = str;
      }
      if (i < 10) {
        pt[id[str]] += A[i];
      }
      ++win[id[str]][i];
    }
  }
  int mi = 0, mj = 0, i;
  for (i = 1; i < (int)id.size(); i++) {
    if (cmp1(i, mi)) mi = i;
    if (cmp2(i, mj)) mj = i;
  }
  printf("%s\n%s\n", w[mi].c_str(), w[mj].c_str());
  return 0;
}
