#include <bits/stdc++.h>
using namespace std;
int points[11] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct T {
  vector<int> a;
  string name;
  T() {
    for (int i = (1); i <= (55); i++) a.push_back(0);
  }
  bool operator<(const T &b) const { return a > b.a; }
} ma[1100];
int n, games;
map<string, int> name;
int main() {
  cin >> games;
  while (games--) {
    int man;
    cin >> man;
    for (int i = (1); i <= (man); i++) {
      string s;
      cin >> s;
      int id = name[s];
      if (id == 0) {
        id = name[s] = ++n;
        ma[id].name = s;
      }
      if (i <= 10) ma[id].a[0] += points[i];
      ma[id].a[i]++;
    }
  }
  sort(ma + 1, ma + n + 1);
  cout << ma[1].name << endl;
  for (int i = (1); i <= (n); i++) swap(ma[i].a[0], ma[i].a[1]);
  sort(ma + 1, ma + n + 1);
  cout << ma[1].name << endl;
  return 0;
}
