//suhan lee, saitama university;
#include <stdio.h>
#define STOP 90
#define space 50
#define ASK 96
int main(){
  int i,j,k,p;
  char inp[1000][60];
  int out[40][40];
  int reout[40];
  char kanglish[39][5]={" ","a","b","c","d","e","f",
"g","h","i","j","k","l","m","n","o","p","q","r","s",
"t","u","v","w","x","y","z","ld","mb","mp",
"nc","nd","ng","nt","nw","ps","qu","cw","ts"};
  scanf("%d ",&p);
  for(i=0;i<p;i++)
    fgets(inp[i],sizeof(inp[p]),stdin);
  //input
  
  for(i=0;i<p;i++)
    for(k=0;inp[i][k]>0;k++)   
      for(j=27;j<39;j++){ 
	if(inp[i][k]==kanglish[j][0]&&inp[i][k+1]==kanglish[j][1])
	  {

	    inp[i][k]=j;
	    inp[i][k+1]=STOP;

	  }
	if(inp[i][k]==' ') inp[i][k]=39;
	if(inp[i][k]=='\n') inp[i][k]=0;
      }
  // translate to kanglish
 
  for(i=0;i<p;i++)
    for(k=0;inp[i][k]!=0;k++) 
      inp[i][k]%=ASK;


  for(i=0;i<40;i++)
    reout[i]=1;
  for(i=0;i<40;i++)
    for(k=0;k<40;k++) 
      out[i][k]=0; 
  //to 0 
  for(i=0;i<p;i++)
    for(k=0;inp[i][k]>0;k++)
      if(inp[i][k+1]==STOP) {
	 out[inp[i][k]][inp[i][k+2]]++;
	 k++;
	}
	else 	 out[inp[i][k]][inp[i][k+1]]++;
  //numbering

  for(i=1;i<39;i++)
    for(j=1;j<39;j++){
      if(out[i][reout[i]]<out[i][j])
	reout[i]=j;

    }
  //search the maximum

  for(i=1;i<39;i++)
    printf("%s %s %d\n",kanglish[i],kanglish[reout[i]],out[i][reout[i]]);
 

  return 0;
}