import sys L = sys.stdin.read().splitlines() L = L[2:] L = [ l.split() for l in L ] D = { tuple(k):v for [k,_,v] in L } print('digraph G {') for ((k,l),v) in D.items(): print(f'{k} -> {v} [label="{l}"];') print("}")