#include <bits/stdc++.h>
using namespace std;
const int pnt[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, vector<int> > g;
vector<pair<vector<int>, string> > mas;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (g.count(s) == 0) g[s] = vector<int>(51, 0);
      g[s][i + 1]--;
      if (i < 10) g[s][0] -= pnt[i];
    }
  }
  for (map<string, vector<int> >::iterator it = g.begin(); it != g.end();
       it++) {
    mas.push_back(make_pair(it->second, it->first));
  }
  sort(mas.begin(), mas.end());
  cout << mas[0].second << endl;
  for (int i = 0; i < mas.size(); i++) {
    swap(mas[i].first[0], mas[i].first[1]);
  }
  sort(mas.begin(), mas.end());
  cout << mas[0].second << endl;
  return 0;
}
