#include <bits/stdc++.h>
const int points[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
const int N = 100;
int n, m, w[N][N], p[N], id[N], k;
char name[N][N], s[N];
bool cmp(int a, int b) {
  if (p[a] != p[b]) return (p[a] > p[b]);
  int i;
  for (i = 0; w[a][i] == w[b][i] && i < k; i++)
    ;
  return w[a][i] > w[b][i];
}
bool cmp2(int a, int b) {
  if (w[a][0] != w[b][0]) return (w[a][0] > w[b][0]);
  if (p[a] != p[b]) return (p[a] > p[b]);
  int i;
  for (i = 1; w[a][i] == w[b][i] && i < k; i++)
    ;
  return w[a][i] > w[b][i];
}
int main() {
  scanf("%d", &n);
  k = 0;
  memset(w, 0, sizeof(w));
  memset(p, 0, sizeof(p));
  for (int i = 0; i < n; i++) {
    scanf("%d\n", &m);
    for (int j = 0; j < m; j++) {
      gets(s);
      int e;
      for (e = 0; e < k; e++)
        if (!strcmp(name[e], s)) break;
      if (e == k) k++, strcpy(name[e], s);
      if (j < 10) p[e] += points[j];
      w[e][j]++;
    }
  }
  for (int i = 0; i < k; i++) id[i] = i;
  std::sort(id, id + k, cmp);
  puts(name[id[0]]);
  std::sort(id, id + k, cmp2);
  puts(name[id[0]]);
}
