import java.util.*;
class S
{
String name[], surname[];
int i,j,n;
String s;
Scanner sc=new Scanner(System.in);
public void show()
{
System.out.print("\nEnter the No of persons:");
n=sc.nextInt();
name=new String[n];
surname=new String[n];
for(i=0;i<n;i++)
{
System.out.print("\nName:");
name[i]=sc.next().toUpperCase();
System.out.print("\nSurname:");
surname[i]=sc.next().toUpperCase();
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(surname[i].compareTo(surname[j])>0)
{
s=surname[i];
surname[i]=surname[j];
surname[j]=s;
s=name[i];
name[i]=name[j];
name[j]=s;
}
}
}
System.out.println("Name with Surname in alphabetical order of surname");
for(i=0;i<n;i++)
System.out.println(name[i]+ " "+surname[i]);
}
}