#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int sc[maxn] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}, w[maxn], num;
string s[maxn];
map<string, int> r;
vector<vector<int>> cnt(1010, vector<int>(60));
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string t;
    for (int i = 0; i < n; i++) {
      cin >> t;
      if (!r.count(t)) {
        s[num] = t;
        r[t] = num++;
      }
      int x = r[t];
      if (i < 10) w[x] += sc[i];
      cnt[x][i]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < num; i++) {
    if (w[ans] < w[i] || w[ans] == w[i] && cnt[ans] < cnt[i]) ans = i;
  }
  cout << s[ans] << "\n";
  ans = 0;
  for (int i = 0; i < num; i++) {
    if (cnt[ans][0] < cnt[i][0] ||
        cnt[ans][0] == cnt[i][0] &&
            (w[ans] < w[i] || w[ans] == w[i] && cnt[ans] < cnt[i]))
      ans = i;
  }
  cout << s[ans] << "\n";
  return 0;
}
