#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
struct driver {
  string name;
  vector<int> places;
  int points;
  driver() {
    places.resize(64);
    points = 0;
  }
  bool operator<(const driver& rhs) const {
    if (points != rhs.points)
      return points < rhs.points;
    else
      return places < rhs.places;
  }
};
int p[64];
int main() {
  int me;
  cin >> me;
  memset(p, 0, sizeof(p));
  int t[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  for (int i = 0; i < 10; i++) p[i] = t[i];
  map<string, driver> m;
  map<string, driver>::iterator itr;
  for (int i = 0; i < me; i++) {
    string name;
    int place = 0;
    int n;
    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> name;
      if ((itr = m.find(name)) == m.end()) {
        driver newDriver;
        newDriver.points = p[place];
        newDriver.name = name;
        newDriver.places[place]++;
        m.insert(make_pair(name, newDriver));
      } else {
        itr->second.points += p[place];
        itr->second.places[place]++;
      }
      place++;
    }
  }
  vector<driver> v;
  for (itr = m.begin(); itr != m.end(); ++itr) {
    v.push_back(itr->second);
  }
  sort(v.rbegin(), v.rend());
  cout << v[0].name << endl;
  for (int i = 0; i < v.size(); i++) swap(v[i].places[0], v[i].points);
  sort(v.rbegin(), v.rend());
  cout << v[0].name << endl;
  return 0;
}
