#!/usr/bin/python3
# Encoding: utf8

# INPUT: trigrams with tags for stopwords
# OUTPUT: a non-zero matrix word-context-freq

import sys
import re
#import math
from collections import defaultdict

matrix = defaultdict(int) ##initializing a dictionary

for line in sys.stdin:  
    line = line.strip()
    line = line.split()
    if len(line) >= 3:
        w1 = line[0]
        w2 = line[1]
        w3 = line[2]
    
    if w1 != "STOP" and w2 != "STOP":
        matrix[w1,w2] += 1
        matrix[w2,w1] += 1

    if w1 != "STOP" and w3 != "STOP":
        matrix[w1,w3] += 1
        matrix[w3,w1] += 1
        

for w,c in matrix:
    print ('%s\t%s\t%d' % (w, c, matrix[w,c]))
        
