#include <bits/stdc++.h>
const int MAX = 55;
const int _rank[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int num_rank[MAX][MAX];
int num_tol[MAX];
using namespace std;
void init() {
  memset(num_rank, 0, sizeof(num_rank));
  memset(num_tol, 0, sizeof(num_tol));
}
bool cmp1(int a, int b) {
  if (num_tol[a] != num_tol[b])
    return num_tol[a] > num_tol[b];
  else {
    for (int i = 0; i < MAX; i++) {
      if (num_rank[a][i] != num_rank[b][i])
        return num_rank[a][i] > num_rank[b][i];
    }
    return 0;
  }
}
bool cmp2(int a, int b) {
  if (num_rank[a][0] != num_rank[b][0])
    return num_rank[a][0] > num_rank[b][0];
  else {
    return cmp1(a, b);
  }
}
int main(void) {
  int cas, m;
  while (cin >> m) {
    string num_to_name[MAX];
    map<string, int> name_to_num;
    init();
    int name_cnt = 0;
    for (int i = 0; i < m; i++) {
      int n;
      cin >> n;
      string name;
      for (int i = 0; i < n; i++) {
        cin >> name;
        if (name_to_num.count(name) == 0) {
          name_to_num[name] = name_cnt++;
          num_to_name[name_cnt - 1] = name;
        }
        int t = name_to_num[name];
        num_rank[t][i]++;
        if (i < 10) {
          num_tol[t] += _rank[i];
        }
      }
    }
    int fin_rank[MAX];
    for (int i = 0; i < name_to_num.size(); i++) fin_rank[i] = i;
    sort(fin_rank, fin_rank + name_to_num.size(), cmp1);
    cout << num_to_name[fin_rank[0]] << endl;
    sort(fin_rank, fin_rank + name_to_num.size(), cmp2);
    cout << num_to_name[fin_rank[0]] << endl;
  }
  return 0;
}
