#include <bits/stdc++.h>
using namespace std;
map<string, bool> m1;
vector<string> v;
int arr[1003][1003], p[1003], arr1[1003], arr2[1003];
string str;
bool cmp1(int a, int b) {
  int i;
  if (p[a] != p[b]) return p[a] > p[b];
  i = 0;
  while (true) {
    if (arr[a][i] != arr[b][i]) return arr[a][i] > arr[b][i];
    i++;
    if (i == 50) break;
  }
  return arr[a][50] > arr[b][50];
}
bool cmp2(int a, int b) {
  int i;
  if (arr[a][0] != arr[b][0]) return arr[a][0] > arr[b][0];
  if (p[a] != p[b]) return p[a] > p[b];
  i = 0;
  while (true) {
    if (arr[a][i] != arr[b][i]) return arr[a][i] > arr[b][i];
    i++;
    if (i == 50) break;
  }
  return arr[a][50] > arr[b][50];
}
int main() {
  int r, i, n, j, k;
  scanf("%d", &r);
  arr2[0] = 25;
  arr2[1] = 18;
  arr2[2] = 15;
  arr2[3] = 12;
  arr2[4] = 10;
  arr2[5] = 8;
  arr2[6] = 6;
  arr2[7] = 4;
  arr2[8] = 2;
  arr2[9] = 1;
  for (k = 0; k < r; k++) {
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      cin >> str;
      if (!m1[str]) {
        m1[str] = 1;
        v.push_back(str);
      }
      for (j = 0; j < v.size(); j++) {
        if (v[j] == str) break;
      }
      p[j] += arr2[i];
      arr[j][i]++;
    }
  }
  for (i = 0; i < v.size(); i++) arr1[i] = i;
  sort(arr1, arr1 + v.size(), cmp1);
  cout << v[arr1[0]] << endl;
  sort(arr1, arr1 + v.size(), cmp2);
  cout << v[arr1[0]] << endl;
  return 0;
}
