#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
map<string, vector<int>> mp1;
bool comp(const pair<int, string> &a, const pair<int, string> &b) {
  if (a.first == b.first) {
    for (int i = 0; i < 59; i++) {
      if (mp1[a.second][i] == mp1[b.second][i])
        continue;
      else
        return mp1[a.second][i] > mp1[b.second][i];
    }
  } else
    return a.first > b.first;
}
bool comp1(const pair<vector<int>, string> &a,
           const pair<vector<int>, string> &b) {
  for (int i = 0; i < 59; i++) {
    if (mp1[a.second][i] == mp1[b.second][i]) {
      if (mp[a.second] == mp[b.second])
        continue;
      else
        return mp[a.second] > mp[b.second];
    } else
      return mp1[a.second][i] > mp1[b.second][i];
  }
}
int main() {
  int t;
  cin >> t;
  int v1[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (i < 10) mp[s] += v1[i];
      if (mp1.find(s) == mp1.end()) mp1[s].resize(59, 0);
      mp1[s][i]++;
    }
  }
  vector<pair<int, string>> v;
  for (auto it : mp) {
    v.push_back({it.second, it.first});
  }
  vector<pair<vector<int>, string>> v2;
  for (auto it : mp1) {
    v2.push_back({it.second, it.first});
  }
  sort(v.begin(), v.end(), comp);
  sort(v2.begin(), v2.end(), comp1);
  cout << v[0].second << endl;
  cout << v2[0].second << endl;
}
