{"raw_statement":[{"iden":"statement","content":"De Prezer loves troyic paths.Consider we have a graph with n vertices and m edges.Edges are directed in one way.And there is at most one edge from any vertex to any other vertex.If there is an edge from v to u, then c(v, u) is its color and w(v, u) is its length.Otherwise,c(v, u) = w(v, u) =  - 1.\n\nA sequence p1, p2, ..., pk is a troyic path is and only if for each 1 ≤ i ≤ k, 1 ≤ pi ≤ n and if i < k, then c(pi, pi + 1) >  - 1 and if i + 1 < k, then c(pi, pi + 1) ≠ c(pi + 1, pi + 2) .\n\nThe length of such troyic path is  and it's called a p1 - pk path.\n\nIn such graph, length of the shortest path from vertex v to u is the minimum length of all v - u paths.(The length of the shortest path from any vertex to itself equals 0)\n\nDe Prezer gives you a graph like above and a vertex s.\n\nDe Prezer also loves query. So he gives you q queries and in each query, gives you number t and you should print the length of the shortest path from s to t (or  - 1 if there is no troyic path from s to t)\n\nThe first line of input contains three integers n and m and C, the number of vertices, the numbers of edges and the number of valid colors.\n\nThe next m lines, each line contains 4 integers v, u, w(v, u), c(v, u) (1 ≤ v, u ≤ n and v ≠ u and 1 ≤ w(v, u) ≤ 109 and 1 ≤ c(v, u) ≤ C).\n\nThe line after that contains integer s and q.\n\nThe next q lines, each line contains information of one query, number t.\n\n1 ≤ n, m, C, q ≤ 105\n\nm ≤ n(n - 1)\n\n1 ≤ s, t ≤ n\n\nFor each query, print the answer.\n\n"},{"iden":"input","content":"The first line of input contains three integers n and m and C, the number of vertices, the numbers of edges and the number of valid colors.The next m lines, each line contains 4 integers v, u, w(v, u), c(v, u) (1 ≤ v, u ≤ n and v ≠ u and 1 ≤ w(v, u) ≤ 109 and 1 ≤ c(v, u) ≤ C).The line after that contains integer s and q.The next q lines, each line contains information of one query, number t.1 ≤ n, m, C, q ≤ 105m ≤ n(n - 1)1 ≤ s, t ≤ n"},{"iden":"output","content":"For each query, print the answer."},{"iden":"examples","content":"Input5 4 10001 2 10 12 3 10 23 4 10 24 5 10 11 512345Output01020-1-1Input5 5 21 2 10 12 3 10 23 4 10 14 5 10 21 5 39 11 512345Output010203039"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ a, b \\in \\mathbb{Z}^+ $ with $ 1 \\leq a, b \\leq 10^5 $.  \n\n**Objective**  \nCompute $ c = \\gcd(a, b) $, and store $ c $ in storage location 1.","simple_statement":"Find the greatest common divisor of a and b, store the result in storage 1.","has_page_source":false}