//dennismv 2008B Readable

#include <iostream>

#include <string>

#include <map>

using namespace std;

 

ostream& operator<<(ostream &os, const pair<string,int> &p)

{

      cout<<p.first<<" "<<p.second;

      return os;

}

 

pair<string,int> getName(int n)

{

      map<string,int> table;

      string s,maxname;

      int max=0;

      for (int i=0;i<n;i++)

      {

            cin>>s;

            table[s]++;

            if (max<table[s])

            {

                  max=table[s];

                  maxname=s;

            }

      }

      return make_pair(maxname,max);

}

 

int main()

{

      int n;

      while (cin>>n && n!=0)

      {

            cout<<getName(n)<<endl;

      }

      return 0;

}