#include <bits/stdc++.h>
using namespace std;
const int mark[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int T, n, a[160], id[160], cur, pos;
map<string, int> mp;
char vis[160][55], s[55];
string Name[160];
bool cmp1(int x, int y) {
  if (a[x] != a[y]) return a[x] > a[y];
  for (int i = 0; i < 50; i++) {
    if (vis[x][i] != vis[y][i]) return vis[x][i] > vis[y][i];
  }
  return 0;
}
bool cmp2(int x, int y) {
  if (vis[x][0] != vis[y][0]) return vis[x][0] > vis[y][0];
  if (a[x] != a[y]) return a[x] > a[y];
  for (int i = 1; i < 50; i++) {
    if (vis[x][i] != vis[y][i]) return vis[x][i] > vis[y][i];
  }
  return 0;
}
int main() {
  cur = 1;
  for (scanf("%d", &T); T--;) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      if (mp[s]) {
        pos = mp[s];
        if (i < 10) a[pos] += mark[i];
        vis[pos][i]++;
      } else {
        mp[s] = cur;
        if (i < 10) a[cur] += mark[i];
        vis[cur][i]++;
        Name[cur++] = s;
      }
    }
  }
  for (int i = 1; i < cur; i++) id[i] = i;
  sort(id + 1, id + cur, cmp1);
  cout << Name[id[1]] << endl;
  sort(id + 1, id + cur, cmp2);
  cout << Name[id[1]] << endl;
}
