#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  map<string, vector<int> > m;
  for (int i = 0; i < n; ++i) {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; ++i) {
      char b[200];
      scanf("%s", b);
      string name(b);
      int pt = 0;
      if (i == 1) pt = 25;
      if (i == 2) pt = 18;
      if (i == 3) pt = 15;
      if (i == 4) pt = 12;
      if (i == 5) pt = 10;
      if (i == 6) pt = 8;
      if (i == 7) pt = 6;
      if (i == 8) pt = 4;
      if (i == 9) pt = 2;
      if (i == 10) pt = 1;
      m[name].resize(51);
      m[name][0] += pt;
      m[name][i] += 1;
    }
  }
  vector<pair<vector<int>, string> > v;
  for (map<string, vector<int> >::iterator it = m.begin(); it != m.end();
       ++it) {
    v.push_back(pair<vector<int>, string>(it->second, it->first));
  }
  sort(v.begin(), v.end());
  printf("%s\n", v[v.size() - 1].second.c_str());
  for (int i = 0; i < v.size(); ++i) {
    swap(v[i].first[0], v[i].first[1]);
  }
  sort(v.begin(), v.end());
  printf("%s\n", v[v.size() - 1].second.c_str());
  return 0;
}
