#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s,mx,mn;
int x,mx2,mn2;
int main(){
while(cin>>s)
{
x=s.size();
if(s[x-x+1]>='a'&&s[x-1]<='z'||s[x-1]>='A'&&s[x-1]<='Z')
{
mx2=max(x,mx2);
mx=s;
mn2=min(x,mn2);
mn=s;
}
else
{
if(mx2<x-1)
{
mx2=x-1;
mx=s;
}
if(mn2>x-1)
{
mn2=x-1;
mn=s;
}
}
}
cout<<mx<<endl<<mn;
return 0;
}