#include <bits/stdc++.h>
using namespace std;
int mark[] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct Node {
  int val, id;
  int num[60];
};
struct Node node[1010];
int n;
map<string, int> mp1;
map<int, string> mp2;
int t, m;
bool cmp1(Node a, Node b) {
  if (a.val != b.val)
    return a.val > b.val;
  else {
    for (int i = 1; i <= 50; i++)
      if (a.num[i] != b.num[i]) return a.num[i] > b.num[i];
  }
}
bool cmp2(Node a, Node b) {
  if (a.num[1] != b.num[1]) return a.num[1] > b.num[1];
  if (a.val != b.val)
    return a.val > b.val;
  else {
    for (int i = 2; i <= 50; i++)
      if (a.num[i] != b.num[i]) return a.num[i] > b.num[i];
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> m;
    for (int i = 1; i <= m; i++) {
      string s;
      cin >> s;
      int id;
      if (mp1[s] == 0) {
        n++;
        mp1[s] = n;
        node[n].id = n;
        mp2[n] = s;
      }
      id = mp1[s];
      if (i <= 10) node[id].val += mark[i];
      node[id].num[i]++;
    }
  }
  sort(node + 1, node + 1 + n, cmp1);
  cout << mp2[node[1].id] << "\n";
  sort(node + 1, node + 1 + n, cmp2);
  cout << mp2[node[1].id] << "\n";
  return 0;
}
