#include <bits/stdc++.h>
using namespace std;
map<string, int> drivers;
vector<string> names;
int points[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
vector<vector<int> > wins;
vector<int> pts;
int cmpWins(int a, int b, int c) {
  if (wins[a][c] > wins[b][c]) {
    return 1;
  } else if (wins[a][c] < wins[b][c]) {
    return -1;
  }
  return 0;
}
bool cmp1(int a, int b) {
  if (pts[a] > pts[b]) {
    return true;
  } else if (pts[a] < pts[b]) {
    return false;
  }
  for (int i = 0; i < 50; i++) {
    int val = cmpWins(a, b, i);
    if (val == 1) {
      return true;
    } else if (val == -1) {
      return false;
    }
  }
  return false;
}
bool cmp2(int a, int b) {
  int val = cmpWins(a, b, 0);
  if (val == 1) {
    return true;
  } else if (val == -1) {
    return false;
  }
  if (pts[a] > pts[b]) {
    return true;
  } else if (pts[a] < pts[b]) {
    return false;
  }
  for (int i = 1; i < 50; i++) {
    int val = cmpWins(a, b, i);
    if (val == 1) {
      return true;
    } else if (val == -1) {
      return false;
    }
  }
  return false;
}
int main() {
  int T;
  scanf("%d", &T);
  int D = 0;
  for (int t = 0; t < T; t++) {
    int N;
    scanf("%d", &N);
    for (int n = 0; n < N; n++) {
      char name[55];
      scanf("%s", name);
      string s(name);
      if (drivers.find(s) == drivers.end()) {
        drivers.insert(make_pair(s, D++));
        names.push_back(s);
        wins.push_back(vector<int>(50, 0));
        if (n < 10) {
          pts.push_back(points[n]);
        } else {
          pts.push_back(0);
        }
      } else {
        if (n < 10) pts[drivers[s]] += points[n];
      }
      wins[drivers[s]][n]++;
    }
  }
  vector<int> ds;
  for (int i = 0; i < D; i++) {
    ds.push_back(i);
  }
  sort(ds.begin(), ds.end(), cmp1);
  printf("%s\n", names[ds[0]].c_str());
  sort(ds.begin(), ds.end(), cmp2);
  printf("%s\n", names[ds[0]].c_str());
}
