#include <bits/stdc++.h>
using namespace std;
int getscore[100] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct peo {
  string name;
  int rank[60];
  int sum;
} A[60];
map<string, int> M;
int cmp1(peo a, peo b) {
  if (a.sum > b.sum)
    return 1;
  else if (a.sum < b.sum)
    return 0;
  else {
    for (int i = 0; i < 50; i++) {
      if (a.rank[i] > b.rank[i])
        return 1;
      else if (a.rank[i] < b.rank[i])
        return 0;
    }
  }
  return 0;
}
int cmp2(peo a, peo b) {
  if (a.rank[0] > b.rank[0])
    return 1;
  else if (a.rank[0] < b.rank[0])
    return 0;
  else if (a.sum > b.sum)
    return 1;
  else if (a.sum < b.sum)
    return 0;
  else {
    for (int i = 1; i < 50; i++) {
      if (a.rank[i] > b.rank[i])
        return 1;
      else if (a.rank[i] < b.rank[i])
        return 0;
    }
  }
  return 0;
}
int main() {
  int i, j, m, n;
  int num = 0;
  string a;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &m);
    for (j = 0; j < m; j++) {
      cin >> a;
      if (!M.count(a)) {
        M[a] = num;
        num++;
        A[M[a]].name = a;
      }
      A[M[a]].rank[j]++;
      A[M[a]].sum += getscore[j];
    }
  }
  sort(A, A + num, cmp1);
  cout << A[0].name << endl;
  sort(A, A + num, cmp2);
  cout << A[0].name;
  return 0;
}
