#include <bits/stdc++.h>
using namespace std;
map<string, vector<int> > m;
int sc[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int calc(const vector<int> &t) {
  int res = 0;
  for (int i = 0; i < (10); ++i) res += sc[i] * t[i];
  return res;
}
struct Cmp1 {
  bool operator()(const vector<int> &a1, const vector<int> &a2) {
    if (calc(a1) != calc(a2)) return calc(a1) > calc(a2);
    return a1 > a2;
  }
};
struct Cmp2 {
  bool operator()(const vector<int> &a1, const vector<int> &a2) {
    if (a1[0] != a2[0]) return a1[0] > a2[0];
    if (calc(a1) != calc(a2)) return calc(a1) > calc(a2);
    return a1 > a2;
  }
};
int main() {
  int t, n;
  string s;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < (n); ++i) {
      cin >> s;
      if (m[s].empty()) m[s] = vector<int>(50, 0);
      m[s][i]++;
    }
  }
  vector<vector<int> > arr;
  for (__typeof((m).begin()) i = ((m).begin()); i != (m).end(); ++i)
    arr.push_back(i->second);
  sort((arr).begin(), (arr).end(), Cmp1());
  for (__typeof((m).begin()) i = ((m).begin()); i != (m).end(); ++i)
    if (i->second == arr[0]) cout << i->first << endl;
  sort((arr).begin(), (arr).end(), Cmp2());
  for (__typeof((m).begin()) i = ((m).begin()); i != (m).end(); ++i)
    if (i->second == arr[0]) cout << i->first << endl;
  return 0;
}
