#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int prime = 9241;
struct rider {
  int score;
  string name;
  vector<int> place;
  rider(string name) : name(name) {
    score = 0;
    place.resize(51, 0);
  }
};
bool ls0(rider a, rider b) {
  if (a.score > b.score) return true;
  if (a.score < b.score) return false;
  int i = 0;
  for (; i < 51 && a.place[i] == b.place[i]; i++)
    ;
  if (a.place[i] > b.place[i]) return true;
  return false;
}
bool ls1(rider a, rider b) {
  if (a.place[0] > b.place[0]) return true;
  if (a.place[0] < b.place[0]) return false;
  if (a.score > b.score) return true;
  if (a.score < b.score) return false;
  int i = 0;
  for (; i < 51 && a.place[i] == b.place[i]; i++)
    ;
  if (a.place[i] > b.place[i]) return true;
  return false;
}
vector<rider> rs;
int cnt = 0;
int main() {
  int t;
  cin >> t;
  int scores[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  map<string, int> r;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      string nm;
      cin >> nm;
      int num = -1;
      if (r.count(nm) == 0) {
        num = cnt++;
        rs.push_back(rider(nm));
        r[nm] = num;
      } else
        num = r[nm];
      rs[num].place[i]++;
      if (i < 10) rs[num].score += scores[i];
    }
  }
  sort(rs.begin(), rs.end(), ls0);
  cout << rs[0].name << endl;
  sort(rs.begin(), rs.end(), ls1);
  cout << rs[0].name << endl;
}
