#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int xx[4] = {1, -1, 0, 0};
const int yy[4] = {0, 0, 1, -1};
int inline in() {
  int x = 0, c;
  for (; (unsigned int)((c = getchar()) - '0') >= 10;) {
    if (c == '-') return -in();
    if (!~c) throw ~0;
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while ((unsigned int)((c = getchar()) - '0') < 10);
  return x;
}
struct driver {
  int sco;
  int p[55];
  string name;
};
const int score[105] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
bool comp1(const pair<driver, string> &x, const pair<driver, string> &y) {
  if (x.first.sco != y.first.sco)
    return x.first.sco > y.first.sco;
  else {
    for (int i = 1; i <= 50; i++) {
      if (x.first.p[i] != y.first.p[i]) return x.first.p[i] > y.first.p[i];
    }
  }
  return true;
}
bool comp2(const pair<driver, string> &x, const pair<driver, string> &y) {
  if (x.first.p[1] != y.first.p[1])
    return x.first.p[1] > y.first.p[1];
  else if (x.first.sco != y.first.sco)
    return x.first.sco > y.first.sco;
  else {
    for (int i = 2; i <= 50; i++) {
      if (x.first.p[i] != y.first.p[i]) return x.first.p[i] > y.first.p[i];
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  int t, n;
  cin >> t;
  map<string, driver> m;
  for (int i = 1; i <= t; i++) {
    cin >> n;
    for (int j = 1; j <= n; j++) {
      string s;
      cin >> s;
      m[s].sco += score[j];
      m[s].p[j]++;
    }
  }
  vector<pair<driver, string> > ans;
  for (map<string, driver>::iterator it = m.begin(); it != m.end(); it++)
    ans.push_back(make_pair(it->second, it->first));
  sort((ans).begin(), (ans).end(), comp1);
  cout << ans.front().second << endl;
  sort((ans).begin(), (ans).end(), comp2);
  cout << ans.front().second << endl;
  return 0;
}
