#include <bits/stdc++.h>
using namespace std;
struct Player {
  string name;
  int score;
  int cnt[55];
  Player() {
    name = "";
    score = 0;
    memset(cnt, 0, sizeof(cnt));
  }
};
Player p[55];
int np;
int ss[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
void add(string name, int rank) {
  for (int i = 0; i < np; i++) {
    if (p[i].name == name) {
      if (rank < 10) {
        p[i].score += ss[rank];
      }
      p[i].cnt[rank]++;
      return;
    }
  }
  p[np].name = name;
  if (rank < 10) {
    p[np].score = ss[rank];
  }
  memset(p[np].cnt, false, sizeof(p[np].cnt));
  p[np].cnt[rank]++;
  np++;
}
bool cmp1(const Player &a, const Player &b) {
  if (a.score != b.score) {
    return a.score > b.score;
  } else {
    for (int i = 0; i < 55; i++) {
      if (a.cnt[i] != b.cnt[i]) {
        return a.cnt[i] > b.cnt[i];
      }
    }
    return a.name < b.name;
  }
}
bool cmp2(const Player &a, const Player &b) {
  if (a.cnt[0] != b.cnt[0]) {
    return a.cnt[0] > b.cnt[0];
  } else if (a.score != b.score) {
    return a.score > b.score;
  } else {
    for (int i = 1; i < 55; i++) {
      if (a.cnt[i] != b.cnt[i]) {
        return a.cnt[i] > b.cnt[i];
      }
    }
    return a.name < b.name;
  }
}
char tmp[55];
int main() {
  int t;
  while (scanf("%d", &t) != EOF) {
    int n;
    np = 0;
    while (t--) {
      scanf("%d", &n);
      for (int i = 0; i < n; i++) {
        scanf("%s", tmp);
        add(string(tmp), i);
      }
    }
    sort(p, p + np, cmp1);
    printf("%s\n", p[0].name.c_str());
    sort(p, p + np, cmp2);
    printf("%s\n", p[0].name.c_str());
  }
  return 0;
}
