#include<stdio.h>
#include<string.h>
const int INF = 40005;
int tire[INF][26], sum[INF], tol = 1;
void insert(char* data,int rt);
void find(char* data);
/*
carbohydrate
cart
carburetor
caramel
caribou
carbonic
cartilage
carbon
carriage
carton
car
carbonate
*/
int main()
{
	char strs[INF][25];
	char str[INF];
	int num = 1;
	while(~scanf("%s",str))
	{
		insert(str,1);
		strcpy(strs[num],str);
		num++;
	}
	for(int i = 1; i < num; i++)
	{
		printf("%s ",strs[i]);
		find(strs[i]);
		printf("\n");
	}
	return 0;
}

void insert(char* data,int rt)
{
	int len = strlen(data);
	for(int i = 0; i < len; i++)
	{
		int y = data[i] - 'a';
		if(tire[rt][y] == 0)
		{
			tire[rt][y] = ++tol;
		}
		sum[tire[rt][y]]++;
		rt = tire[rt][y];
	}
}
void find(char* data)
{
	int len = strlen(data);
	int rt = 1;
	for(int i = 0; i < len; i++)
	{
		int y = data[i] - 'a';
		if(sum[tire[rt][y]] == 1)
		{
			printf("%c",data[i]);	
			return ;
		}
		else
		{
			printf("%c",data[i]);
		}
		rt = tire[rt][y];
	} 
	return ;
	
}