#include <bits/stdc++.h>
using namespace std;
int pts[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct P {
  int places[64];
  int points;
  P() {
    memset(places, 0, sizeof(places));
    points = 0;
  }
};
bool cp1(const pair<string, P>& aa, const pair<string, P>& bb) {
  const P& a = aa.second;
  const P& b = bb.second;
  if (a.points != b.points)
    return a.points > b.points;
  else
    for (int i = 0;; i++)
      if (a.places[i] != b.places[i]) return a.places[i] > b.places[i];
}
bool cp2(const pair<string, P>& aa, const pair<string, P>& bb) {
  const P& a = aa.second;
  const P& b = bb.second;
  if (a.places[0] != b.places[0])
    return a.places[0] > b.places[0];
  else if (a.points != b.points)
    return a.points > b.points;
  else
    for (int i = 1;; i++)
      if (a.places[i] != b.places[i]) return a.places[i] > b.places[i];
}
int main() {
  map<string, P> ps;
  int T;
  scanf("%d", &T);
  char buf[128];
  while (T--) {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
      scanf("%s", buf);
      P& p = ps[buf];
      p.places[i]++;
      if (i < 10) p.points += pts[i];
    }
    vector<pair<string, P> > vs(ps.begin(), ps.end());
  }
  printf("%s\n", min_element(ps.begin(), ps.end(), cp1)->first.c_str());
  printf("%s\n", min_element(ps.begin(), ps.end(), cp2)->first.c_str());
  return 0;
}
