#include <bits/stdc++.h>
using namespace std;
struct team {
  string name;
  int score;
  int scores[64];
  team() {
    for (int i = 0; i < 64; i++) {
      scores[i] = 0;
    }
    score = 0;
  }
};
map<string, int> m;
struct team a[1024];
int emtiaz[64] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int cmp1(const void *a, const void *b) {
  struct team t1, t2;
  t1 = *(struct team *)a;
  t2 = *(struct team *)b;
  if (t1.score > t2.score) return -1;
  if (t1.score < t2.score) return 1;
  for (int i = 0; i < 64; i++) {
    if (t1.scores[i] > t2.scores[i]) return -1;
    if (t1.scores[i] < t2.scores[i]) return 1;
  }
  return 0;
}
int cmp2(const void *a, const void *b) {
  struct team t1, t2;
  t1 = *(struct team *)a;
  t2 = *(struct team *)b;
  if (t1.scores[0] > t2.scores[0]) return -1;
  if (t1.scores[0] < t2.scores[0]) return 1;
  if (t1.score > t2.score) return -1;
  if (t1.score < t2.score) return 1;
  for (int i = 1; i < 64; i++) {
    if (t1.scores[i] > t2.scores[i]) return -1;
    if (t1.scores[i] < t2.scores[i]) return 1;
  }
  return 0;
}
int main() {
  int n, k;
  int cnt = 1;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> s;
      if (!m[s]) {
        m[s] = cnt++;
        struct team t;
        t.name = s;
        t.score = emtiaz[j];
        t.scores[j]++;
        a[cnt - 2] = t;
      } else {
        a[m[s] - 1].score += emtiaz[j];
        a[m[s] - 1].scores[j]++;
      }
    }
  }
  qsort(a, cnt - 1, sizeof(struct team), cmp1);
  cout << a[0].name << endl;
  qsort(a, cnt - 1, sizeof(struct team), cmp2);
  cout << a[0].name << endl;
  return 0;
}
