#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
const long long INF = 1000000000;
const int MAXN = 128;
int points[] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int t, n;
map<string, vector<int> > places;
map<string, int> score;
struct T {
  string name;
  vector<int> place;
  int score;
};
bool cmp1(const T& a, const T& b) {
  if (a.score != b.score) return a.score > b.score;
  for (int i = 1; i <= 55; ++i)
    if (a.place[i] != b.place[i]) return a.place[i] > b.place[i];
  return a.name < b.name;
}
bool cmp2(const T& a, const T& b) {
  if (a.place[1] != b.place[1]) return a.place[1] > b.place[1];
  if (a.score != b.score) return a.score > b.score;
  for (int i = 2; i <= 55; ++i)
    if (a.place[i] != b.place[i]) return a.place[i] > b.place[i];
  return a.name < b.name;
}
int main() {
  cin >> t;
  for (int tt = 0; tt < t; ++tt) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      string s;
      cin >> s;
      int kk = 0;
      if (i <= 10) kk = points[i];
      score[s] += kk;
      if (places.find(s) == places.end()) places[s] = vector<int>(60);
      places[s][i]++;
    }
  }
  map<string, int>::iterator it;
  vector<T> a;
  for (it = score.begin(); it != score.end(); ++it) {
    a.push_back(T());
    a.back().name = it->first;
    a.back().place = places[it->first];
    a.back().score = it->second;
  }
  sort((a).begin(), (a).end(), cmp1);
  cout << a[0].name << endl;
  sort((a).begin(), (a).end(), cmp2);
  cout << a[0].name << endl;
}
