#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
char bj[20];
char name[50];
}Stu;
int cmp(const void *e1, const void *e2) {
if ( strcmp(((Stu *)e1)->bj, ((Stu *)e2)->bj) < 0 )
return -1;
else if ( strcmp(((Stu *)e1)->bj, ((Stu *)e2)->bj) > 0 )
return 1;
else {
if (( strcmp(((Stu *)e1)->name, ((Stu *)e2)->name) <= 0 ) )
return -1;
return 1;
}
}
int main()
{
Stu U[125];
int n = 0;
while(scanf("%s %s", &U[n].name, &U[n].bj ) != EOF) {
n++;
}
qsort(U, n , sizeof(struct Node), cmp);
for (int i = 0; i < n; i ++ ){
printf("%s %s\n", U[i].bj, U[i].name);
}
return 0;
}