#include <bits/stdc++.h>
using namespace std;
int place_to_score[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int t, n;
map<string, int> ids;
int next_id = 1;
char names[50][64];
char tmp[64];
int score[50];
int places[50][50];
int main() {
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    scanf("%d", &n);
    int place = 0;
    for (int j = 0; j < n; j++) {
      scanf("%s", tmp);
      int id = ids[tmp];
      if (!id) {
        ids[tmp] = id = next_id++;
        strcpy(names[id - 1], tmp);
      }
      id--;
      if (place < 10) score[id] += place_to_score[place];
      places[id][place]++;
      place++;
    }
  }
  vector<int> best;
  int points = -1;
  for (int i = 0; i < next_id - 1; i++) {
    if (score[i] > points) {
      best.clear();
      points = score[i];
    }
    if (score[i] == points) best.push_back(i);
  }
  for (int place = 0; best.size() > 1 && place < next_id - 1; place++) {
    vector<int> new_best;
    points = -1;
    for (int i = 0; i < best.size(); i++) {
      if (places[best[i]][place] > points) {
        new_best.clear();
        points = places[best[i]][place];
      }
      if (places[best[i]][place] == points) new_best.push_back(best[i]);
    }
    best = new_best;
  }
  printf("%s\n", names[best[0]]);
  best.clear();
  points = -1;
  for (int i = 0; i < next_id - 1; i++) {
    if (places[i][0] > points) {
      best.clear();
      points = places[i][0];
    }
    if (places[i][0] == points) best.push_back(i);
  }
  if (best.size() > 1) {
    vector<int> new_best;
    points = -1;
    for (int i = 0; i < best.size(); i++) {
      if (score[best[i]] > points) {
        new_best.clear();
        points = score[best[i]];
      }
      if (score[best[i]] == points) new_best.push_back(best[i]);
    }
    best = new_best;
  }
  for (int place = 1; best.size() > 1 && place < next_id - 1; place++) {
    vector<int> new_best;
    points = -1;
    for (int i = 0; i < best.size(); i++) {
      if (places[best[i]][place] > points) {
        new_best.clear();
        points = places[best[i]][place];
      }
      if (places[best[i]][place] == points) new_best.push_back(best[i]);
    }
    best = new_best;
  }
  printf("%s\n", names[best[0]]);
}
