#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
struct cand {
  string name;
  int score;
  int win[55];
};
int n, t, cnt = 0;
int sc[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, cand> mp;
inline bool cmp1(const cand &a, const cand &b) {
  if (a.score != b.score) return a.score > b.score;
  for (int i = 0; i < 50; i++)
    if (a.win[i] != b.win[i]) return a.win[i] > b.win[i];
}
inline bool cmp2(const cand &a, const cand &b) {
  if (a.win[0] != b.win[0]) return a.win[0] > b.win[0];
  if (a.score != b.score) return a.score > b.score;
  for (int i = 1; i < 50; i++)
    if (a.win[i] != b.win[i]) return a.win[i] > b.win[i];
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    cand &x = mp[s];
    x.name = s;
    if (i < 10) x.score += sc[i];
    x.win[i]++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) solve();
  vector<cand> v;
  for (map<string, cand>::iterator it = mp.begin(); it != mp.end(); it++)
    v.push_back(it->second);
  sort(v.begin(), v.end(), cmp1);
  cout << v[0].name << endl;
  sort(v.begin(), v.end(), cmp2);
  cout << v[0].name << endl;
  return 0;
}
