import std.stdio;void main(){int[][]n;int[int]h;int a,b,c;for(;~scanf("%s%s%d",&a,&b,&c);h[b]=-c)n~=[c,a,b],h[a]=c;n.sort;foreach(p;n){a=h[p[1]],b=h[p[2]];printf("%c %s %s %d ",a-b?84:70,&p[1],&p[2],*p);foreach(ref d;h)d==b&&(d=a);}}
Note that non-ascii characters in the above source code will be escaped (such as \x9f).