You are given a directed graph with $$$n$$$ vertices and $$$m$$$ edges. There may be multiple edges between same pair of vertices. Self-loops are also allowed in this graph. The vertices are labeled by $$$1,2,\dots,n$$$. The length of the $$$i$$$-th edge $$$u_i\rightarrow v_i$$$ is $$$998\,244\,353^{w_i}$$$.
Your task is to find a cycle in the given graph such that the average length of all edges on the cycle is minimized, or determine there is no cycle.
The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 100$$$), the number of test cases. For each test case:
The first line contains two positive integers $$$n$$$ and $$$m$$$ ($$$1\leq n\leq 1000$$$, $$$1\leq m\leq 2000$$$), denoting the number of vertices and edges.
Each of the following $$$m$$$ lines contains three integers $$$u_i,v_i$$$ and $$$w_i$$$ ($$$1\leq u_i,v_i\leq n$$$, $$$0\leq w_i \lt n$$$), describing an edge.
It is guaranteed that there are at most $$$10$$$ cases such that $$$n \gt 100$$$ or $$$m \gt 100$$$.
For each test case, output a single line containing an integer, denoting the average length of all edges on the cycle that you find.
More precisely, if the answer is $$$\frac{p}{q}$$$, you should output the minimum non-negative integer $$$r$$$ such that $$$q \cdot r \equiv p \pmod{(10^9+7)}$$$. You may safely assume that such $$$r$$$ always exists in all test cases. But if there is no cycle, please print "-1" instead.
63 31 2 02 3 03 1 02 11 2 02 21 2 02 1 13 51 2 01 3 12 3 23 2 02 3 14 51 2 32 3 33 1 32 4 14 1 11 11 1 0
1 -1 499122177 499122177 540815376 1