In the first line of the standard input there are two positive integers and , separated by a single space. They are the number of towns in Byteotia and the number of roads connecting the towns, respectively. The towns are numbered from to .
In each of successive lines there are three integers separated by single spaces: and , . Each triple describes one one-way road of length enabling to move from the town to . For each two towns there exist at most one road that enables to move in the given direction.
In the following line there is one integer , denoting the number of queries. In the successive lines there are queries written, one per line. Each query has a form of three integers separated by single spaces: and . Such a query refers to the length of the -th shortest route from the town to the town .