#include <bits/stdc++.h>
using namespace std;
long long n;
void solve();
vector<vector<pair<long long, long long>>> x;
vector<long long> visited;
long long ct = 0;
long long rcount = 0;
long long flag = 0;
long long last;
void dfs(long long y) {
  last = y;
  if (flag == 0 && y == 0) {
    flag = 1;
    visited[y] = 1;
  } else {
    visited[y] = 1;
  }
  for (long long i = 0; i < x[y].size(); i++) {
    if (visited[x[y][i].first] != 1) {
      if (x[y][i].second > 0)
        ct += x[y][i].second;
      else {
        rcount += x[y][i].second;
      }
      dfs(x[y][i].first);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
void solve() {
  long long t;
  cin >> t;
  map<string, long long> x;
  map<long long, string> xx;
  vector<pair<vector<long long>, string>> vv;
  long long index = 0;
  vv.assign(50, pair<vector<long long>, string>());
  for (long long i = 0; i < 50; i++) {
    for (long long j = 0; j < 51; j++) {
      vv[i].first.push_back(0);
    }
    vv[i].second = "";
  }
  long long points[50] = {0};
  long long pts[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  for (long long i = 0; i < t; i++) {
    long long n;
    cin >> n;
    for (long long j = 0; j < n; j++) {
      string temp;
      cin >> temp;
      if (x.count(temp) == 0) {
        x[temp] = index;
        xx[index] = temp;
        if (j <= 9) vv[index].first[0] -= pts[j];
        vv[index].first[j + 1] -= 1;
        vv[index].second = xx[index];
        index++;
      } else {
        if (j <= 9) vv[x[temp]].first[0] -= pts[j];
        vv[x[temp]].first[j + 1] -= 1;
      }
    }
  }
  sort(vv.begin(), vv.end());
  cout << vv[0].second << endl;
  for (long long i = 0; i < 50; i++) {
    long long temp = vv[i].first[0];
    long long temp2 = vv[i].first[1];
    vv[i].first[0] = temp2;
    vv[i].first[1] = temp;
  }
  sort(vv.begin(), vv.end());
  cout << vv[0].second;
  return;
}
