{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e“Weird Mazes” are defined as the following: \u003c/p\u003e\u003cp\u003e * The maze has rectangular shape, it has N rows and M columns of rooms. \u003c/p\u003e\u003cp\u003e* The rows are numbered from 1 to N top to down, the columns are numbered from 1 to M left to right.\u003c/p\u003e\u003cp\u003e * Each room is connected to at most 6 other rooms, through magical doors, these room are not necessarily the usual top, down, left, or right room. \u003c/p\u003e\u003cp\u003e * To move from room \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ex\u003c/i\u003e1, \u003ci\u003ey\u003c/i\u003e1\u003c/sub\u003e\u003c/span\u003e ,\u003cspan class\u003d\"tex-font-style-tt\"\u003e\"row x1 and column y1\"\u003c/span\u003e, to room \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ex\u003c/i\u003e2, \u003ci\u003ey\u003c/i\u003e2\u003c/sub\u003e\u003c/span\u003e, it costs an amount of money C ( \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003eC\u003c/i\u003e ≤ 1000\u003c/span\u003e ). In addition, when you move from one room to another you spend T years, where ( \u003cspan class\u003d\"tex-span\"\u003e - 100 ≤ \u003ci\u003eT\u003c/i\u003e ≤ + 100\u003c/span\u003e ), that means: if T is positive, then you are travelling to the future. If T is negative, then you are travelling to the past!\u003c/p\u003e\u003cp\u003eA friend of yours, Tareq, is at room \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ex\u003c/i\u003e, \u003ci\u003ey\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e, it’s now the year 0. Tareq wants to travel to the room \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ea\u003c/i\u003e, \u003ci\u003eb\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e, and arrive there exactly in year w, another big problem is: during the trip, the absolute value of time can never exceed 100, In other words: Tareq should always stay in the [-100, +100] time range, because if he didn\u0027t, he will be lost in the maze for ever !! \u003c/p\u003e\u003cp\u003e Can you help Tareq to know the minimum cost of money for him trip? \u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line will be the number of test cases Tc. Each test case starts with four integers in a single line: \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003eN\u003c/i\u003e ≤ 100\u003c/span\u003e, the number of rows in the maze, \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003eM\u003c/i\u003e ≤ 100\u003c/span\u003e, the number of columns, \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003ex\u003c/i\u003e ≤ \u003ci\u003eN\u003c/i\u003e\u003c/span\u003e , \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003ey\u003c/i\u003e ≤ \u003ci\u003eM\u003c/i\u003e\u003c/span\u003e , the initial position of Tareq meaning that he is in room \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ex\u003c/i\u003e, \u003ci\u003ey\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e, (Remember he starts at year 0). The second line contains an integer p, the number of connections between rooms in the maze. Then p lines follow, each describe a connection and contains six integers: \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003ex\u003c/i\u003e1 ≤ \u003ci\u003eN\u003c/i\u003e\u003c/span\u003e , \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003ey\u003c/i\u003e1 ≤ \u003ci\u003eM\u003c/i\u003e\u003c/span\u003e , \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003ex\u003c/i\u003e2 ≤ \u003ci\u003eN\u003c/i\u003e\u003c/span\u003e , \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003ey\u003c/i\u003e2 ≤ \u003ci\u003eM\u003c/i\u003e\u003c/span\u003e , \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003eC\u003c/i\u003e ≤ 1000\u003c/span\u003e , \u003cspan class\u003d\"tex-span\"\u003e - 100 ≤ \u003ci\u003eT\u003c/i\u003e ≤ + 100\u003c/span\u003e , Which means that there is a one way connection from room \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ex\u003c/i\u003e1, \u003ci\u003ey\u003c/i\u003e1\u003c/sub\u003e\u003c/span\u003e , to room \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ex\u003c/i\u003e2, \u003ci\u003ey\u003c/i\u003e2\u003c/sub\u003e\u003c/span\u003e , with cost C of money and T of time. Follows a line containing one integer q, the numbers of queries, each query consists of three integers: \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003ea\u003c/i\u003e ≤ \u003ci\u003eN\u003c/i\u003e\u003c/span\u003e , \u003cspan class\u003d\"tex-span\"\u003e0 \u0026lt; \u003ci\u003eb\u003c/i\u003e ≤ \u003ci\u003eM\u003c/i\u003e\u003c/span\u003e , \u003cspan class\u003d\"tex-span\"\u003e - 100 ≤ \u003ci\u003ew\u003c/i\u003e ≤ 100\u003c/span\u003e , which means: what is the minimum cost of money that Tareq has to pay in order to reach room \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ea\u003c/i\u003e, \u003ci\u003eb\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e at year w? Starting from the initial position \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eR\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ex\u003c/i\u003e, \u003ci\u003ey\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e. \u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case, you should print \"Case c:\" \u003cspan class\u003d\"tex-span\"\u003e\u003c/span\u003e without quotes where c is the number of the test case starting from 1, then for each query you should print one integer on a separated line, the solution to the query. If it is impossible to achieve, just print the word \"No\" \u003cspan class\u003d\"tex-span\"\u003e\u003c/span\u003e without quotes, see the sample output for more details.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\n2 2 1 1\n1\n1 1 2 2 5 1\n1\n2 2 1\n3 6 1 1\n5\n1 1 2 5 1 -5\n2 5 1 2 1 -7\n1 1 1 2 1 5\n1 1 1 3 1 3\n1 2 1 3 1 8\n4\n1 1 0\n1 2 5\n1 3 13\n1 3 3\n2 2 1 1\n4 1\n1 2 2 1 5\n2 2 1 1 2 5\n1 1 2 2 3 -5\n2 2 1 1 4 -5\n1\n2 2 17\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\n5\nCase 2:\n0\n1\n2\n1\nCase 3:\nNo\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}