#include <bits/stdc++.h>
using namespace std;
int point[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct Champion {
  string name;
  int point;
  int time[51];
};
bool cmp1(Champion a, Champion b) {
  if (a.point > b.point) return true;
  if (a.point == b.point) {
    for (int i = 0; i < 50; i++) {
      if (a.time[i] > b.time[i]) return true;
      if (a.time[i] == b.time[i]) continue;
      return false;
    }
  }
  return false;
}
bool cmp2(Champion a, Champion b) {
  if (a.time[0] > b.time[0]) return true;
  if (a.time[0] == b.time[0]) {
    if (a.point > b.point) return true;
    if (a.point == b.point) {
      for (int i = 1; i < 50; i++) {
        if (a.time[i] > b.time[i]) return true;
        if (a.time[i] == b.time[i]) continue;
        return false;
      }
    }
  }
  return false;
}
int main() {
  int n;
  while (cin >> n) {
    vector<Champion> C;
    while (n--) {
      int N;
      cin >> N;
      for (int i = 0; i < N; i++) {
        string name;
        cin >> name;
        bool flag = false;
        for (int j = 0; j < C.size(); j++) {
          if (C[j].name == name) {
            flag = true;
            if (i < 10) {
              C[j].point += point[i];
            }
            C[j].time[i]++;
            break;
          }
        }
        if (flag == false) {
          Champion t;
          t.name = name;
          t.point = 0;
          memset(t.time, 0, sizeof(t.time));
          if (i < 10) t.point += point[i];
          t.time[i]++;
          C.push_back(t);
        }
      }
    }
    sort(C.begin(), C.end(), cmp1);
    cout << C[0].name << endl;
    sort(C.begin(), C.end(), cmp2);
    cout << C[0].name << endl;
  }
  return 0;
}
