#include <bits/stdc++.h>
using namespace std;
const int w[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> score, standing[50];
bool cmp1(const string &a, const string &b) {
  if (score[a] > score[b]) return true;
  if (score[a] < score[b]) return false;
  for (int i = 0; i < 50; i++) {
    if (standing[i][a] > standing[i][b]) return true;
    if (standing[i][a] < standing[i][b]) return false;
  }
  return true;
}
bool cmp2(const string &a, const string &b) {
  if (standing[0][a] > standing[0][b]) return true;
  if (standing[0][a] < standing[0][b]) return false;
  if (score[a] > score[b]) return true;
  if (score[a] < score[b]) return false;
  for (int i = 1; i < 50; i++) {
    if (standing[i][a] > standing[i][b]) return true;
    if (standing[i][a] < standing[i][b]) return false;
  }
  return true;
}
int main() {
  vector<string> list;
  string name;
  int t, n, i;
  score.clear();
  for (i = 0; i < 50; i++) standing[i].clear();
  for (cin >> t; t; t--)
    for (cin >> n, i = 0; i < n; i++) {
      cin >> name, standing[i][name]++;
      if (i < 10) score[name] += w[i];
    }
  list.clear();
  for (map<string, int>::iterator p = score.begin(); p != score.end(); p++)
    list.push_back(p->first);
  sort(list.begin(), list.end(), cmp1);
  cout << *list.begin() << endl;
  sort(list.begin(), list.end(), cmp2);
  cout << *list.begin() << endl;
  return 0;
}
