#include <bits/stdc++.h>
using namespace std;
int score[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
class Cont {
 public:
  string name;
  int point;
  int nums[51];
};
vector<Cont> all;
Cont temp_Cont;
bool check_A(Cont A, Cont B) {
  if (A.point != B.point) return (A.point > B.point);
  for (int i = 0; i < 51; i++) {
    if (A.nums[i] == B.nums[i])
      continue;
    else
      return (A.nums[i] > B.nums[i]);
  }
  return true;
}
bool check_B(Cont A, Cont B) {
  if (A.nums[0] != B.nums[0]) return (A.nums[0] > B.nums[0]);
  if (A.point != B.point) return (A.point > B.point);
  for (int i = 1; i < 51; i++) {
    if (A.nums[i] == B.nums[i])
      continue;
    else
      return (A.nums[i] > B.nums[i]);
  }
  return true;
}
int mysort(int n) {
  int ret = 0;
  for (int i = 1; i < all.size(); i++) {
    if ((n == 0 && !check_A(all[ret], all[i])) ||
        (n == 1 && !check_B(all[ret], all[i]))) {
      ret = i;
    }
  }
  return ret;
}
int main() {
  int t, n;
  cin >> t;
  for (int i = 0; i < 51; i++) temp_Cont.nums[i] = 0;
  temp_Cont.point = 0;
  temp_Cont.name = "";
  for (int i = 0; i < t; i++) {
    cin >> n;
    for (int j = 0; j < n; j++) {
      string temp;
      cin >> temp;
      int k;
      for (k = 0; k < all.size(); k++)
        if (all[k].name == temp) break;
      if (k == all.size()) {
        all.push_back(temp_Cont);
        all[k].name = temp;
      }
      if (j < 10) all[k].point += score[j];
      all[k].nums[j]++;
    }
  }
  cout << all[mysort(0)].name << endl;
  cout << all[mysort(1)].name << endl;
  return 0;
}
