#include <bits/stdc++.h>
using namespace std;
int point[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> mm;
map<int, string> mm2;
struct node {
  int p;
  int a[2000];
  int pos;
} per[2000];
int id = 0;
int getid(string s) {
  if (mm.find(s) == mm.end()) {
    mm[s] = id++;
    mm2[id - 1] = s;
    return id - 1;
  } else
    return mm[s];
}
bool cmp1(node a, node b) {
  if (a.p != b.p) return a.p > b.p;
  int i;
  for (i = 0; i < 100; i++)
    if (a.a[i] != b.a[i]) return a.a[i] > b.a[i];
  return false;
}
bool cmp2(node a, node b) {
  if (a.a[0] != b.a[0]) return a.a[0] > b.a[0];
  if (a.p != b.p) return a.p > b.p;
  int i;
  for (i = 0; i < id; i++)
    if (a.a[i] != b.a[i]) return a.a[i] > b.a[i];
  return false;
}
int main() {
  int ca;
  scanf("%d", &ca);
  mm.clear();
  mm2.clear();
  while (ca--) {
    int n;
    scanf("%d", &n);
    string s;
    int i;
    for (i = 0; i < n; i++) {
      cin >> s;
      int k = getid(s);
      if (i < 10) {
        per[k].p += point[i];
      }
      per[k].a[i]++;
      per[k].pos = k;
    }
  }
  sort(per, per + id, cmp1);
  cout << mm2[per[0].pos] << endl;
  sort(per, per + id, cmp2);
  cout << mm2[per[0].pos] << endl;
  return 0;
}
