#include <bits/stdc++.h>
using namespace std;
struct racer {
  int points;
  int was[50];
};
int b[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, racer> m;
bool check1(racer r1, racer r2) {
  if (r1.points != r2.points) return r1.points > r2.points;
  for (int i = 0; i < 50; i++) {
    if (r1.was[i] != r2.was[i]) return r1.was[i] > r2.was[i];
  }
  return false;
}
bool check2(racer r1, racer r2) {
  if (r1.was[0] != r2.was[0]) return r1.was[0] > r2.was[0];
  return check1(r1, r2);
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      string nam;
      cin >> nam;
      if (i < 10) m[nam].points += b[i];
      m[nam].was[i]++;
    }
  }
  string w1 = m.begin()->first;
  string w2 = w1;
  for (map<string, racer>::iterator it = m.begin(); it != m.end(); it++) {
    if (check1(it->second, m[w1])) w1 = it->first;
    if (check2(it->second, m[w2])) w2 = it->first;
  }
  cout << w1 << endl << w2;
  return 0;
}
