#include <bits/stdc++.h>
using namespace std;
char tmp_str[1000];
string scanf_string() {
  scanf("%s", tmp_str);
  return tmp_str;
}
map<string, int> mapik;
vector<string> amapik;
int dodaj(string a) {
  if (mapik.count(a) == 0) {
    mapik[a] = mapik.size() - 1;
    amapik.push_back(a);
  }
  return mapik[a];
}
const int N = 100;
int wins[N][N];
int points[N];
int t, n;
int pointst[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int order[N];
int method1(int a, int b) {
  if (points[a] == points[b]) {
    for (int i = 0; i < N; i++) {
      if (wins[a][i] != wins[b][i]) {
        return wins[a][i] > wins[b][i];
      }
    }
  } else
    return points[a] > points[b];
}
int method2(int a, int b) {
  if (wins[a][0] == wins[b][0]) {
    if (points[a] != points[b]) {
      return points[a] > points[b];
    } else {
      for (int i = 1; i < N; i++) {
        if (wins[a][i] != wins[b][i]) {
          return wins[a][i] > wins[b][i];
        }
      }
    }
  } else
    return wins[a][0] > wins[b][0];
}
int main() {
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    scanf("%d", &n);
    for (int i2 = 0; i2 < n; i2++) {
      string name = scanf_string();
      wins[dodaj(name)][i2]++;
      if (i2 < 10) {
        points[dodaj(name)] += pointst[i2];
      }
    }
  }
  int drivers = mapik.size();
  for (int i2 = 0; i2 < drivers; i2++) order[i2] = i2;
  sort(order, order + drivers, method1);
  printf("%s\n", amapik[order[0]].c_str());
  for (int i2 = 0; i2 < drivers; i2++) order[i2] = i2;
  sort(order, order + drivers, method2);
  printf("%s\n", amapik[order[0]].c_str());
  return 0;
}
