Relative Relatives

Time limit1sMemory limit128 MB

Problem

Today is Ted's 100th birthday. A few weeks ago the family chose you to track down all of Ted's descendants and throw a surprise party. To make the job easier, you decide to build a single list of everyone descended from Ted, ordered from oldest to youngest. Descendants who are the same age are listed in dictionary order.

The only records you have are birth certificates. Strangely, none of them are dated. Each certificate lists only three things: the father's name, the child's name, and the father's exact age (in whole years) at the moment the child was born.

Because every descendant of Ted shares Ted's birthday, the age gap between any two people is always a whole number of years. Ted turns 100 today, so his age is 100.

Input

The first line contains a single integer $n$, the number of data sets. Each data set is formatted as follows.

A data set has two parts:

  1. Descendant count — a line with a single integer $X$ ($0 < X < 100$), the number of Ted's descendants.
  2. Birth certificate list — $X$ lines, one certificate per line, each in the format FNAME CNAME FAGE, where:
    • FNAME is the father's name.
    • CNAME is the child's name.
    • FAGE is the father's whole-year age on the day CNAME was born.

Notes:

  • Names are unique identifiers and contain no embedded whitespace.
  • Every descendant of Ted shares Ted's birthday, so the age difference between any two of them is a whole number of years.
  • The certificates are a complete collection: there is exactly one certificate for every descendant of Ted.

Output

For each data set, print $X + 1$ lines. The first line is DATASET Y, where $Y$ is $1$ for the first data set, $2$ for the second, and so on. The next $X$ lines are the age-prioritized list of Ted's descendants, one per line in the format NAME AGE, ordered from oldest to youngest. Descendants of the same age are listed in dictionary order.