#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
const int points[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int n, t, cnt = 0;
vector<pair<string, int> > v;
map<string, int> mp;
string name[maxn];
int score[maxn], win[55][maxn];
inline bool better1(int a, int b) {
  if (score[a] != score[b]) return score[a] > score[b];
  if (win[0][a] != win[0][b]) return win[0][a] > win[0][b];
  for (int i = 1; i < 55; i++)
    if (win[i][a] != win[i][b]) return win[i][a] > win[i][b];
  return false;
}
inline bool better2(int a, int b) {
  if (win[0][a] != win[0][b]) return win[0][a] > win[0][b];
  if (score[a] != score[b]) return score[a] > score[b];
  for (int i = 1; i < 55; i++)
    if (win[i][a] != win[i][b]) return win[i][a] > win[i][b];
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      v.push_back(make_pair(s, i));
    }
  }
  for (int i = 0; i < v.size(); i++) mp[v[i].first] = 0;
  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    name[cnt] = it->first;
    it->second = cnt;
    cnt++;
  }
  for (int i = 0; i < v.size(); i++) {
    int mark = mp[v[i].first];
    int rank = v[i].second;
    if (rank < 10) score[mark] += points[rank];
    win[rank][mark]++;
  }
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < cnt; i++) {
    if (better1(i, ans1)) ans1 = i;
    if (better2(i, ans2)) ans2 = i;
  }
  cout << name[ans1] << endl << name[ans2] << endl;
  return 0;
}
