#include <bits/stdc++.h>
using namespace std;
struct node {
  char name[55];
  int score;
  int c[50];
} comp[55];
int cmp1(node x, node y) {
  if (x.score > y.score)
    return 1;
  else if (x.score == y.score) {
    for (int i = 0; i < 50; i++)
      if (x.c[i] > y.c[i])
        return 1;
      else if (x.c[i] < y.c[i])
        return 0;
  } else
    return 0;
}
int cmp2(node x, node y) {
  if (x.c[0] > y.c[0])
    return 1;
  else if (x.c[0] == y.c[0]) {
    if (x.score > y.score)
      return 1;
    else if (x.score == y.score) {
      for (int i = 1; i < 50; i++)
        if (x.c[i] > y.c[i])
          return 1;
        else if (x.c[i] < y.c[i])
          return 0;
    } else
      return 0;
  } else
    return 0;
}
int s[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int main() {
  int t;
  while (scanf("%d", &t) != EOF) {
    memset(comp, 0, sizeof(comp));
    int sum = 0;
    while (t--) {
      int n, i;
      char na[55];
      scanf("%d", &n);
      for (i = 0; i < n; i++) {
        scanf("%s", na);
        int j;
        for (j = 0; j < sum; j++) {
          if (strcmp(comp[j].name, na) == 0) {
            if (i < 10) comp[j].score += s[i];
            comp[j].c[i]++;
            break;
          }
        }
        if (j == sum) {
          strcpy(comp[sum].name, na);
          if (i < 10) comp[sum].score += s[i];
          comp[sum].c[i]++;
          sum++;
        }
      }
    }
    sort(comp, comp + sum, cmp1);
    printf("%s\n", comp[0].name);
    sort(comp, comp + sum, cmp2);
    printf("%s\n", comp[0].name);
  }
  return 0;
}
