#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}


int main(){

	char words[39][3];
	for(int i = 1; i <= 26; i++){
		words[i][0] = 'a'+i-1;
		words[i][1] = '\0';
	}
	strcpy(words[27],"ld");
	strcpy(words[28],"mb");
	strcpy(words[29],"mp");
	strcpy(words[30],"nc");
	strcpy(words[31],"nd");
	strcpy(words[32],"ng");
	strcpy(words[33],"nt");
	strcpy(words[34],"nw");
	strcpy(words[35],"ps");
	strcpy(words[36],"qu");
	strcpy(words[37],"cw");
	strcpy(words[38],"ts");

	int table[39][39];
	for(int i = 0; i <= 38; i++){
		for(int k = 0; k <= 38; k++)table[i][k] = 0;
	}

	int N;
	scanf("%d",&N);

	char buf[101];

	int pre;

	string S;

	getchar();

	for(int loop = 0; loop < N; loop++){
		fgets(buf,100,stdin);

		pre = 0;
		for(int i = 0; buf[i] != '\0' && buf[i] != '\n';){

			if(buf[i] == 'l' || buf[i] == 'm' || buf[i] == 'n' || buf[i] == 'p' || buf[i] == 'q' || buf[i] == 'c' || buf[i] == 't'){
				switch(buf[i]){
				case 'l':
					if(buf[i+1] == 'd'){
						table[pre][27]++;
						pre = 27;
						i += 2;
					}else{
						table[pre][buf[i]-'a'+1]++;
						pre = buf[i]-'a'+1;
						i += 1;
					}
					break;
				case 'm':
					switch(buf[i+1]){
					case 'b':
						table[pre][28]++;
						pre = 28;
						i += 2;
						break;
					case 'p':
						table[pre][29]++;
						pre = 29;
						i += 2;
						break;
					default:
						table[pre][buf[i]-'a'+1]++;
						pre = buf[i]-'a'+1;
						i += 1;
						break;
					}
					break;
				case 'n':
					switch(buf[i+1]){
					case 'c':
						table[pre][30]++;
						pre = 30;
						i += 2;
						break;
					case 'd':
						table[pre][31]++;
						pre = 31;
						i += 2;
						break;
					case 'g':
						table[pre][32]++;
						pre = 32;
						i += 2;
						break;
					case 't':
						table[pre][33]++;
						pre = 33;
						i += 2;
						break;
					case 'w':
						table[pre][34]++;
						pre = 34;
						i += 2;
						break;
					default:
						table[pre][buf[i]-'a'+1]++;
						pre = buf[i]-'a'+1;
						i += 1;
						break;
					}
					break;
				case 'p':
					if(buf[i+1] == 's'){
						table[pre][35]++;
						pre = 35;
						i += 2;
					}else{
						table[pre][buf[i]-'a'+1]++;
						pre = buf[i]-'a'+1;
						i += 1;
					}
					break;
				case 'q':
					if(buf[i+1] == 'u'){
						table[pre][36]++;
						pre = 36;
						i += 2;
					}else{
						table[pre][buf[i]-'a'+1]++;
						pre = buf[i]-'a'+1;
						i += 1;
					}
					break;
				case 'c':
					if(buf[i+1] == 'w'){
						table[pre][37]++;
						pre = 37;
						i += 2;
					}else{
						table[pre][buf[i]-'a'+1]++;
						pre = buf[i]-'a'+1;
						i += 1;
					}
					break;
				case 't':
					if(buf[i+1] == 's'){
						table[pre][38]++;
						pre = 38;
						i += 2;
					}else{
						table[pre][buf[i]-'a'+1]++;
						pre = buf[i]-'a'+1;
						i += 1;
					}
					break;
				}
			}else if(buf[i] == ' '){
				pre = 0;
				i += 1;
			}else{
				table[pre][buf[i]-'a'+1]++;
				pre = buf[i]-'a'+1;
				i += 1;
			}
		}
	}

	int maximum,max_index;

	for(int i = 1; i <= 38; i++){
		printf("%s ",words[i]);
		maximum = -1;
		for(int k = 1; k <= 38; k++){
			if(maximum < table[i][k]){
				maximum = table[i][k];
				max_index = k;
			}
		}
		printf("%s %d\n",words[max_index],maximum);
	}

	return 0;
}

Measured memory_bytes: 3088