#include <bits/stdc++.h>
using namespace std;
int s[55] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int t, n = 0;
struct driver {
  string name;
  int score;
  int win[55];
  driver() {
    score = 0;
    memset(win, 0, sizeof(win));
    name = "";
  }
} d[55];
bool cmp1(driver a, driver b) {
  if (a.score > b.score) return 1;
  if (a.score < b.score) return 0;
  for (int i = 1;; i++) {
    if (a.win[i] > b.win[i]) return 1;
    if (a.win[i] < b.win[i]) return 0;
  }
}
bool cmp2(driver a, driver b) {
  if (a.win[1] > b.win[1]) return 1;
  if (a.win[1] < b.win[1]) return 0;
  if (a.score > b.score) return 1;
  if (a.score < b.score) return 0;
  for (int i = 2;; i++) {
    if (a.win[i] > b.win[i]) return 1;
    if (a.win[i] < b.win[i]) return 0;
  }
}
int find(string x) {
  for (int i = 1; i <= n; i++) {
    if (d[i].name == x) return i;
  }
  return 0;
}
void test() {
  for (int i = 1; i <= n; i++) {
    cout << d[i].name << " " << d[i].score << " ";
    for (int j = 1; j <= 10; j++) {
      cout << d[i].win[j] << " ";
    }
    cout << endl;
  }
}
int main() {
  string temporary;
  int temp;
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    scanf("%d", &temp);
    for (int j = 1; j <= temp; j++) {
      cin >> temporary;
      int f = find(temporary);
      if (f != 0) {
        d[f].score += s[j];
        d[f].win[j]++;
      } else {
        n++;
        d[n].name = temporary;
        d[n].score += s[j];
        d[n].win[j]++;
      }
    }
  }
  driver winner1, winner2;
  for (int i = 1; i <= n; i++) {
    if (cmp1(d[i], winner1) == 1) winner1 = d[i];
    if (cmp2(d[i], winner2) == 1) winner2 = d[i];
  }
  printf("%s\n%s\n", winner1.name.data(), winner2.name.data());
  return 0;
}
