#include <bits/stdc++.h>
using namespace std;
struct people {
  string name;
  int score;
  int ci[60];
} p[1500];
int sc[11] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> map1;
bool compare1(people a, people b) {
  if (a.score != b.score)
    return a.score > b.score;
  else {
    for (int i = 1; i <= 60; i++) {
      if (a.ci[i] != b.ci[i]) {
        return a.ci[i] > b.ci[i];
      }
    }
  }
}
bool compare2(people a, people b) {
  if (a.ci[1] != b.ci[1])
    return a.ci[1] > b.ci[1];
  else if (a.score != b.score) {
    return a.score > b.score;
  } else {
    for (int i = 2; i <= 60; i++) {
      if (a.ci[i] != b.ci[i]) {
        return a.ci[i] > b.ci[i];
      }
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  for (int i = 0; i < 1500; i++) {
    for (int j = 0; j < 60; j++) {
      p[i].ci[j] = 0;
    }
  }
  int num = 0;
  for (int i = 0; i < t; i++) {
    int k;
    cin >> k;
    for (int j = 1; j <= k; j++) {
      string s1;
      cin >> s1;
      if (map1.find(s1) == map1.end()) {
        num++;
        map1[s1] = num;
        p[num].name = s1;
        if (j <= 10) p[num].score += sc[j];
        p[num].ci[j]++;
      } else {
        if (j <= 10) p[map1[s1]].score += sc[j];
        p[map1[s1]].ci[j]++;
      }
    }
  }
  sort(p + 1, p + 1 + num, compare1);
  cout << p[1].name << endl;
  sort(p + 1, p + 1 + num, compare2);
  cout << p[1].name << endl;
  return 0;
}
