#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
struct P {
  string name;
  int s;
  int w;
  vector<int> rank;
} p[MAXN];
bool cmp1(const P& a, const P& b) {
  if (a.s == b.s) {
    int i = 0;
    while (1) {
      if (a.rank[i] == b.rank[i]) {
        i++;
        if (a.rank.size() == i)
          return 0;
        else if (b.rank.size() == i)
          return 1;
        continue;
      } else
        return a.rank[i] < b.rank[i];
    }
  }
  return a.s > b.s;
}
bool cmp2(const P& a, const P& b) {
  if (a.w == b.w) {
    if (a.s == b.s) {
      int i = 0;
      while (1) {
        if (a.rank[i] == b.rank[i]) {
          i++;
          if (a.rank.size() == i)
            return 0;
          else if (b.rank.size() == i)
            return 1;
          continue;
        } else
          return a.rank[i] < b.rank[i];
      }
    } else
      return a.s > b.s;
  }
  return a.w > b.w;
}
int main() {
  int n;
  int a[100] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
  while (cin >> n) {
    for (int i = 0; i < MAXN; i++) p[i].rank.clear(), p[i].s = 0;
    set<string> str;
    set<string>::iterator ps;
    int k = 0;
    for (int i = 0; i < n; i++) {
      int m;
      string name;
      cin >> m;
      for (int j = 0; j < m; j++) {
        cin >> name;
        if (str.find(name) == str.end()) {
          str.insert(name);
          p[k].name = name;
          p[k].s = a[j];
          if (j == 0) p[k].w++;
          p[k].rank.push_back(j);
          k++;
        } else {
          for (int h = 0; h < k; h++) {
            if (name == p[h].name) {
              p[h].s += a[j];
              if (j == 0) p[h].w++;
              p[h].rank.push_back(j);
              break;
            }
          }
        }
      }
    }
    for (int i = 0; i < k; i++) sort(p[i].rank.begin(), p[i].rank.end());
    sort(p, p + k, cmp1);
    cout << p[0].name << endl;
    sort(p, p + k, cmp2);
    cout << p[0].name << endl;
  }
  return 0;
}
