#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int main(int argc, char **argv) {
  ifstream from;
  const int Tmax = 20, nmax = 50;
  int T, n, m, rt, i, j, i0, j0, k, l, nm, rt1, rt2, ax;
  int err = 0;
  int ij[nmax], sp[nmax];
  int pr[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  char ch;
  string s[nmax];
  string st, s1, s2;
  vector<vector<int>> b(nmax);
  for (i = 0; i < nmax; i++) b[i].resize(nmax);
  for (i = 0; i < nmax; i++) {
    sp[i] = 0;
    for (j = 0; j < nmax; j++) {
      b[i][j] = 0;
    }
  }
  cin >> T;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s[i];
    b[i][i]++;
    if (i < 10) sp[i] += pr[i];
  }
  nm = i;
  for (k = 1; k < T; k++) {
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> st;
      ax = 0;
      for (j = 0; j < nm; j++) {
        if (st == s[j]) {
          b[j][i]++;
          if (i < 10) sp[j] += pr[i];
          ax = 1;
          break;
        }
      }
      if (ax == 0) {
        s[nm] = st;
        b[nm][i]++;
        if (i < 10) sp[nm] += pr[i];
        nm++;
      }
    }
  }
  for (i = 0; i < nm; i++) {
    ij[i] = i;
  }
  for (i = 0; i < nm - 1; i++) {
    for (j = i + 1; j < nm; j++) {
      if (sp[ij[j]] > sp[ij[i]]) {
        rt = ij[i];
        ij[i] = ij[j];
        ij[j] = rt;
        continue;
      }
      if (sp[ij[j]] == sp[ij[i]]) {
        i0 = 0;
      start1:
        rt1 = b[ij[i]][i0];
        rt2 = b[ij[j]][i0];
        if (rt2 > rt1) {
          rt = ij[i];
          ij[i] = ij[j];
          ij[j] = rt;
          continue;
        } else if ((rt2 == rt1) && (i0 < nm - 1)) {
          i0++;
          goto start1;
        }
      }
    }
  }
  s1 = s[ij[0]];
  for (i = 0; i < nm - 1; i++) {
    for (j = i + 1; j < nm; j++) {
      i0 = 0;
      rt1 = b[ij[i]][i0];
      rt2 = b[ij[j]][i0];
      if (rt2 > rt1) {
        rt = ij[i];
        ij[i] = ij[j];
        ij[j] = rt;
        continue;
      } else if (rt2 == rt1) {
        if (sp[ij[j]] > sp[ij[i]]) {
          rt = ij[i];
          ij[i] = ij[j];
          ij[j] = rt;
          continue;
        }
      }
    }
  }
  s2 = s[ij[0]];
  cout << s1 << endl;
  cout << s2 << endl;
  return 0;
}
