#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int xx[4] = {1, -1, 0, 0};
const int yy[4] = {0, 0, 1, -1};
int inline in() {
  int x = 0, c;
  for (; (unsigned int)((c = getchar()) - '0') >= 10;) {
    if (c == '-') return -in();
    if (!~c) throw ~0;
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while ((unsigned int)((c = getchar()) - '0') < 10);
  return x;
}
struct driver {
  int sco;
  int p[55];
  string name;
} a[105];
const int score[105] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
bool comp1(const driver &x, const driver &y) {
  if (x.sco != y.sco)
    return x.sco > y.sco;
  else {
    for (int i = 1; i <= 50; i++) {
      if (x.p[i] != y.p[i]) return x.p[i] > y.p[i];
    }
  }
  return true;
}
bool comp2(const driver &x, const driver &y) {
  if (x.p[1] != y.p[1])
    return x.p[1] > y.p[1];
  else if (x.sco != y.sco)
    return x.sco > y.sco;
  else {
    for (int i = 2; i <= 50; i++) {
      if (x.p[i] != y.p[i]) return x.p[i] > y.p[i];
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  int t, n;
  cin >> t;
  map<string, int> m;
  int pos = 1;
  for (int i = 1; i <= t; i++) {
    cin >> n;
    for (int j = 1; j <= n; j++) {
      string s;
      cin >> s;
      if (m.find(s) == m.end()) {
        m[s] = pos;
        a[m[s]].name = s;
        pos++;
      }
      a[m[s]].sco += score[j];
      a[m[s]].p[j]++;
    }
  }
  sort(a + 1, a + ((int)(m).size()) + 1, comp1);
  cout << a[1].name << endl;
  sort(a + 1, a + ((int)(m).size()) + 1, comp2);
  cout << a[1].name << endl;
  return 0;
}
