#include <bits/stdc++.h>
using namespace std;
int const ans[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int t, n, total, places[100][100], points[100];
string st, names[100];
map<string, int> mas;
int get_point(int j) {
  if (j < 10) return ans[j];
  return 0;
}
int get_num(string st) {
  map<string, int>::iterator iter = mas.find(st);
  if (iter == mas.end()) {
    names[total] = st;
    mas[st] = total++;
    return total - 1;
  }
  return iter->second;
}
int best(vector<int> &a, vector<int> &b) {
  for (int i = 0; i < (int)a.size(); i++)
    if (a[i] < b[i])
      return 0;
    else if (a[i] > b[i])
      return 1;
  return 0;
}
void get_best_v(vector<vector<int> > &v, int &num) {
  num = 0;
  for (int i = 1; i < total; i++)
    if (best(v[i], v[num])) num = i;
}
int main() {
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> st;
      int v = get_num(st);
      places[v][j]++;
      points[v] += get_point(j);
    }
  }
  vector<vector<int> > v1, v2;
  int num1, num2;
  v1.resize(total);
  v2.resize(total);
  for (int i = 0; i < total; i++) {
    v1[i].push_back(points[i]);
    for (int j = 0; j <= 50; j++) v1[i].push_back(places[i][j]);
    v2[i].push_back(places[i][0]);
    v2[i].push_back(points[i]);
    for (int j = 1; j <= 50; j++) v2[i].push_back(places[i][j]);
  }
  get_best_v(v1, num1);
  get_best_v(v2, num2);
  cout << names[num1] << endl << names[num2];
  return 0;
}
