#include <bits/stdc++.h>
const int position_points[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct racer {
  int points;
  std::string name;
  std::vector<int> score;
  racer(std::string n) : points(0), name(n) { score.resize(55); }
  bool operator<(const racer& o) const {
    if (points == o.points) return score < o.score;
    return points < o.points;
  }
};
bool proposed_system(const racer a, const racer b) {
  if (a.score.front() == b.score.front() && a.points != b.points)
    return a.points < b.points;
  return a.score < b.score;
}
int main(void) {
  int n_races, n_racers;
  std::string name;
  std::vector<racer> racer_vector;
  std::map<std::string, int> racer_map;
  std::cin >> n_races;
  for (int i = 0; i < n_races; ++i) {
    std::cin >> n_racers;
    for (int j = 0; j < n_racers; ++j) {
      std::cin >> name;
      if (!racer_map.count(name)) {
        racer_map[name] = racer_vector.size();
        racer_vector.push_back(racer(name));
      }
      ++racer_vector[racer_map[name]].score[j];
      if (j < 10) racer_vector[racer_map[name]].points += position_points[j];
    }
  }
  std::sort(racer_vector.begin(), racer_vector.end());
  std::cout << racer_vector.back().name << std::endl;
  std::sort(racer_vector.begin(), racer_vector.end(), proposed_system);
  std::cout << racer_vector.back().name << std::endl;
  return 0;
}
