#include <bits/stdc++.h>
using namespace std;
struct P {
  int point;
  string name;
  int cnt[100];
} ans[60];
const int p[50] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
bool cmp1(P a, P b) {
  if (a.point != b.point) return a.point > b.point;
  int i = 1;
  while (a.cnt[i] == b.cnt[i]) i++;
  return a.cnt[i] > b.cnt[i];
}
bool cmp2(P a, P b) {
  if (a.cnt[1] != b.cnt[1]) return a.cnt[1] > b.cnt[1];
  if (a.point != b.point) return a.point > b.point;
  int i = 2;
  while (a.cnt[i] == b.cnt[i]) i++;
  return a.cnt[i] > b.cnt[i];
}
int main(void) {
  int n, t, m = 0;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      string s;
      cin >> s;
      int j = 0;
      while (j < m && ans[j].name != s) j++;
      if (j == m) {
        ans[j].name = s;
        ans[j].point = 0;
        memset(ans[j].cnt, 0, sizeof(ans[j].cnt));
        m++;
      }
      ans[j].point += p[i];
      ans[j].cnt[i]++;
    }
  }
  sort(ans, ans + m, cmp1);
  cout << ans[0].name << endl;
  sort(ans, ans + m, cmp2);
  cout << ans[0].name << endl;
  return 0;
}
