#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
struct Driver {
  string name;
  int pc[64];
  int points;
};
map<string, int> dict;
int getId(string str) {
  if (dict.find(str) == dict.end()) {
    int n = dict.size();
    dict[str] = n;
    return n;
  }
  return dict[str];
}
Driver driver[64];
int score[64] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
bool cmpA(const Driver& a, const Driver& b) {
  if (a.points != b.points) return a.points > b.points;
  for (int i = 0; i < 64; i++)
    if (a.pc[i] != b.pc[i]) return a.pc[i] > b.pc[i];
  return false;
}
bool cmpB(const Driver& a, const Driver& b) {
  if (a.pc[0] != b.pc[0]) return a.pc[0] > b.pc[0];
  if (a.points != b.points) return a.points > b.points;
  for (int i = 1; i < 20; i++)
    if (a.pc[i] != b.pc[i]) return a.pc[i] > b.pc[i];
  return false;
}
int main() {
  int race;
  cin >> race;
  for (int r = 0; r < (int)(race); ++r) {
    int N;
    cin >> N;
    for (int i = 0; i < (int)(N); ++i) {
      string name;
      cin >> name;
      int id = getId(name);
      driver[id].points += score[i];
      ++driver[id].pc[i];
      driver[id].name = name;
    }
  }
  int M = dict.size();
  sort(driver, driver + M, cmpA);
  cout << driver[0].name << endl;
  sort(driver, driver + M, cmpB);
  cout << driver[0].name << endl;
  return 0;
}
