#include <bits/stdc++.h>
using namespace std;
const int points[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> score;
map<string, vector<int> > pos;
bool comp1(const string& s1, const string& s2) {
  if (score[s1] != score[s2]) return score[s1] > score[s2];
  return pos[s1] > pos[s2];
}
bool comp2(const string& s1, const string& s2) {
  if (pos[s1][0] != pos[s2][0]) return pos[s1][0] > pos[s2][0];
  if (score[s1] != score[s2]) return score[s1] > score[s2];
  for (int i = (int)(1); i < ((int)60); i++)
    if (pos[s1][i] != pos[s2][i]) return pos[s1][i] > pos[s2][i];
  return false;
}
int main() {
  int t;
  cin >> t;
  for (int _ = 0; _ < (int)(t); _++) {
    int n;
    cin >> n;
    for (int i = 0; i < (int)(n); i++) {
      string s;
      cin >> s;
      if (i < 10)
        score[s] += points[i];
      else
        score[s] += 0;
      if (!pos.count(s)) pos[s] = vector<int>(60, 0);
      pos[s][i]++;
    }
  }
  vector<string> res;
  for (map<string, vector<int> >::iterator it = pos.begin(); it != pos.end();
       it++)
    res.push_back(it->first);
  sort((res).begin(), (res).end(), comp1);
  cout << res[0] << endl;
  sort((res).begin(), (res).end(), comp2);
  cout << res[0] << endl;
  return 0;
}
