{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\nYou travel a lot by bus and the costs of all the seperate tickets are starting to add up.\n\u003c/p\u003e\n\n\u003cp\u003e\nTherefore you want to see if it might be advantageous for you to buy a bus pass.\n\u003c/p\u003e\n\n\u003cp\u003e\nThe way the bus system works in your country (and also in the Netherlands) is as follows:\n\u003c/p\u003e\n\n\u003cp\u003e\nwhen you buy a bus pass, you have to indicate a center zone and a star value. You are allowed to travel freely in any zone which has a distance to your center zone which is less than your star value. For example, if you have a star value of one, you can only travel in your center zone. If you have a star value of two, you can also travel in all adjacent zones, et cetera.\n\u003c/p\u003e\n\n\u003cp\u003e\nYou have a list of all bus trips you frequently make, and would like to determine the minimum star value you need to make all these trips using your buss pass. But this is not always an easy task. For example look at the following figure:\n\u003c/p\u003e\n\n\u003cp\u003e\n\u003c/p\u003e\u003ccenter\u003e\u003cimg src\u003d\"CDN_BASE_URL/6674dbd8613a69f6e1ec43f24586a8d8?v\u003d1718895136\"\u003e\u003cbr\u003e\u003c/center\u003e\n\nHere you want to be able to travel from A to B and from B to D. The best center zone is 7400, for which you only need a star value of 4. Note that you do not even visit this zone on your trips!\n\u003cp\u003e\u003c/p\u003e\n\n\u003cp\u003e\u003cb\u003eInput\u003c/b\u003e\u003c/p\u003e\n\n\u003cp\u003e\nOn the first line an integer\u003ci\u003et\u003c/i\u003e(1 \u0026lt;\u003d\u003ci\u003et\u003c/i\u003e\u0026lt;\u003d 100): the number of test cases. Then for each test case:\n\u003c/p\u003e\n\n\u003cp\u003e\nOne line with two integers\u003ci\u003enz\u003c/i\u003e(2 \u0026lt;\u003d\u003ci\u003enz\u003c/i\u003e\u0026lt;\u003d 9 999) and\u003ci\u003enr\u003c/i\u003e(1 \u0026lt;\u003d\u003ci\u003enr\u003c/i\u003e\u0026lt;\u003d 10): the number of zones and the number of bus trips, respectively.\n\u003c/p\u003e\n\n\u003cp\u003e\n\u003ci\u003enz\u003c/i\u003e lines starting with two integers \u003ci\u003eid\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e (1 \u0026lt;\u003d id\u003csub\u003ei\u003c/sub\u003e \u0026lt;\u003d 9 999) and \u003ci\u003emz\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e (1 \u0026lt;\u003d \u003ci\u003emz\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e \u0026lt;\u003d 10), a number identifying the i-th zone and the number of zones adjacent to it, followed by mz\u003csub\u003ei\u003c/sub\u003e integers: the numbers of the adjacent zones.\n\u003c/p\u003e\n\n\u003cp\u003e\n\u003ci\u003enr\u003c/i\u003e lines starting with one integer \u003ci\u003emr\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e (1 \u0026lt;\u003d \u003ci\u003emr\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e \u0026lt;\u003d 20), indicating the number of zones the ith bus trip visits, followed by \u003ci\u003emr\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e integers: the numbers of the zones through which the bus passes in the order in which they are visited.\n\u003c/p\u003e\n\n\u003cp\u003e\nAll zones are connected, either directly or via other zones.\n\u003c/p\u003e\n\n\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e\u003c/p\u003e\n\n\u003cp\u003e\nFor each test case:\n\u003c/p\u003e\n\n\u003cp\u003e\nOne line with two integers, the minimum star value and the id of a center zone which achieves this minimum star value. If there are multiple possibilities, choose the zone with the lowest number.\n\u003c/p\u003e\n\n\u003cp\u003e\u003cb\u003eSample Input\u003c/b\u003e\u003c/p\u003e\n\n\u003cp\u003e\n1\u003cbr\u003e\n17 2\u003cbr\u003e\n7400 6 7401 7402 7403 7404 7405 7406\u003cbr\u003e\n7401 6 7412 7402 7400 7406 7410 7411\u003cbr\u003e\n7402 5 7412 7403 7400 7401 7411\u003cbr\u003e\n7403 6 7413 7414 7404 7400 7402 7412\u003cbr\u003e\n7404 5 7403 7414 7415 7405 7400\u003cbr\u003e\n7405 6 7404 7415 7407 7408 7406 7400\u003cbr\u003e\n7406 7 7400 7405 7407 7408 7409 7410 7401\u003cbr\u003e\n7407 4 7408 7406 7405 7415\u003cbr\u003e\n7408 4 7409 7406 7405 7407\u003cbr\u003e\n7409 3 7410 7406 7408\u003cbr\u003e\n7410 4 7411 7401 7406 7409\u003cbr\u003e\n7411 5 7416 7412 7402 7401 7410\u003cbr\u003e\n7412 6 7416 7411 7401 7402 7403 7413\u003cbr\u003e\n7413 3 7412 7403 7414\u003cbr\u003e\n7414 3 7413 7403 7404\u003cbr\u003e\n7415 3 7404 7405 7407\u003cbr\u003e\n7416 2 7411 7412\u003cbr\u003e\n5 7409 7408 7407 7405 7415\u003cbr\u003e\n6 7415 7404 7414 7413 7412 7416\u003cbr\u003e\n\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\u003cb\u003eSample Output\u003c/b\u003e\u003c/p\u003e\n\n\u003cp\u003e\n4 7400\u003cbr\u003e\n\u003c/p\u003e\n\n"}}]}