#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
map<string,int> color;
int main()
{
int n,max;
string str;
map<string,int>::iterator iter;
while(cin>>n&&n)
{
color.clear();
max=0;
while(n--)
{
cin>>str;
++color[str];
}
iter=color.begin();
while(iter!=color.end())
{
max=max>iter->second?max:iter->second;
iter++;
}
cout<<str<<endl;
iter=color.begin();
while(iter!=color.end())
{
if(iter->second==max)
{
cout<<iter->first<<endl;
break;
}
else
iter++;
}
}
return 0;
}
#include <map>
#include <string>
#include <algorithm>
using namespace std;
map<string,int> color;
int main()
{
int n,max;
string str;
map<string,int>::iterator iter;
while(cin>>n&&n)
{
color.clear();
max=0;
while(n--)
{
cin>>str;
++color[str];
}
iter=color.begin();
while(iter!=color.end())
{
max=max>iter->second?max:iter->second;
iter++;
}
cout<<str<<endl;
iter=color.begin();
while(iter!=color.end())
{
if(iter->second==max)
{
cout<<iter->first<<endl;
break;
}
else
iter++;
}
}
return 0;
}