#include <bits/stdc++.h>
using namespace std;
vector<int> v1[1100];
vector<int> v2[1100];
int cnt[1100][60];
int pts[1100];
map<string, int> s2i;
vector<string> i2s;
const int plpts[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      int p;
      if (!s2i.count(s)) {
        p = i2s.size();
        s2i[s] = p;
        i2s.push_back(s);
      } else
        p = s2i[s];
      if (i < 10) pts[p] += plpts[i];
      ++cnt[p][i];
    }
  }
  int n = i2s.size();
  for (int i = 0; i < n; ++i) {
    v1[i].push_back(pts[i]);
    for (int j = 0; j < 50; ++j) v1[i].push_back(cnt[i][j]);
    v1[i].push_back(i);
    v2[i].push_back(cnt[i][0]);
    v2[i].push_back(pts[i]);
    for (int j = 1; j < 50; ++j) v2[i].push_back(cnt[i][j]);
    v2[i].push_back(i);
  }
  sort(v1, v1 + n);
  sort(v2, v2 + n);
  reverse(v1, v1 + n);
  reverse(v2, v2 + n);
  cout << i2s[v1[0].back()] << endl << i2s[v2[0].back()];
  return 0;
}
