#include <bits/stdc++.h>
using namespace std;
vector<int> P = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> id;
class driver {
 public:
  string name;
  int points;
  int wins[51];
  driver(string _name) {
    name = _name;
    points = 0;
    memset(wins, 0, sizeof wins);
  }
  void calc(int p, int w) {
    points += p;
    wins[w]++;
  }
};
class comp1 {
 public:
  int operator()(const driver& d1, const driver& d2) {
    if (d1.points != d2.points) return d1.points > d2.points;
    for (int i = 0; i < 51; i++) {
      if (d1.wins[i] != d2.wins[i]) return d1.wins[i] > d2.wins[i];
    }
    return 0;
  }
};
class comp2 {
 public:
  int operator()(const driver& d1, const driver& d2) {
    if (d1.wins[0] != d2.wins[0]) return d1.wins[0] > d2.wins[0];
    if (d1.points != d2.points) return d1.points > d2.points;
    for (int i = 1; i < 50; i++) {
      if (d1.wins[i] != d2.wins[i]) return d1.wins[i] > d2.wins[i];
    }
    return 0;
  }
};
int main() {
  vector<driver> Driv;
  for (int i = 0; i < 50; i++) P.push_back(0);
  int T;
  cin >> T;
  for (int c = 0; c < T; c++) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (id.count(s)) {
        int ind = id[s];
        Driv[ind].calc(P[i], i);
      } else {
        id[s] = (int)Driv.size();
        driver d(s);
        d.calc(P[i], i);
        Driv.push_back(d);
      }
    }
  }
  sort(Driv.begin(), Driv.end(), comp1());
  cout << Driv[0].name << endl;
  sort(Driv.begin(), Driv.end(), comp2());
  cout << Driv[0].name << endl;
  return 0;
}
