{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eLife is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpected places and unexpected people. Now our journey of Xian ends. To be carefully considered are the following questions.\u003c/p\u003e\n\u003cp\u003eA few months later in Qingdao, an essential ACM competition had been scheduled. But before the competition, we need to attend a wedding in Shanghai. And after the competition, we will leave the country from Shanghai, so Pudong International Airport (Pudong in short) is the end of our tour.\u003c/p\u003e\n\u003cp\u003eHere we have some vital information and missions we have to accomplish.\u003c/p\u003e\n\u003cp\u003eWe have a VIP card of CNAC. For each airport we can enjoy the special VIP services in the departure floor and the arrival floor once respectively. For the pleasure of traveling, it is intolerant without VIP services. That is say that for each airport we can leave from it only once, but without regard to the last flight leaving the country from Pudong, Shanghai. Meanwhile, for each airport we can arrive at it only once.\u003c/p\u003e\n\u003cp\u003eAll as we know, Shanghai has two airports, Hongqiao Airport (Hongqiao in short) and Pudong. Arriving at one and then leaving from another one is a spurned thing. But fortunately there is a nice and evil compensation service. Having a pair of transfer records between Hongqiao and Pudong in both directions, we can obtain a sensible compensation. Actually, we only consider planes in our tour, with the only exception in Shanghai. The exception is that we can arrive and leave Shanghai at different airports. However, if we decide so the compensation described above is necessary. Before the end of our tour, we will pass through Shanghai twice, once for the wedding and another time for the final departure. If we want to obtain the compensation, in the first time we must transfer from Pudong to Hongqiao, and in the second time we will transfer from Hongqiao to Pudong.\u003c/p\u003e\n\u003cp\u003eSimilar transfers between airports in other city are not allowed. If we arrived at a city, we would not go to an airport in an adjacent city by car, bus or interurban railway as well.\u003c/p\u003e\n\u003cp\u003eNow, all available flights between airports are known. We have plenty of time yet. So we do not have any restriction about the number of times. What we require is the smallest total cost of flights throughout the whole tour.\u003c/p\u003e\n\u003cp\u003eHere we go.\u003c/p\u003e\n\u003ch2 id\u003d\"input\"\u003eInput\u003c/h2\u003e\n\u003cp\u003eThere are several test cases. The first line of input contains an integer t (1 ≤ t ≤ 160) which is the total number of test cases. For each test case, the first line contains an integer m (m ≤ 10000) which is the number of known flights. Each of the following m lines describes a flight which contains two string indicating the names of two airports and an integer between 1 and 255 indicating the cost. The flight connects two given airports and it is bidirectional. The name of each airport is an non-empty string with English letters that are no longer than 10. We use “Xian” to present the only airport in Xian, and use “Qingdao” to present the only airport in Qingdao. The airports in Shanghai are described as “Hongqiao” and “Pudong” respectively.\u003c/p\u003e\n\u003ch2 id\u003d\"output\"\u003eOutput\u003c/h2\u003e\n\u003cp\u003eFor each test case, output the smallest total cost, or output −1 if it is impossible.\u003c/p\u003e\n"}},{"title":"Sample 1","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\n4\nXian Hongqiao 3\nXian Pudong 4\nQingdao Hongqiao 4\nQingdao Pudong 3\n4\nXian Hongqiao 4\nXian Pudong 3\nQingdao Hongqiao 3\nQingdao Pudong 4\n6\nXian Hongqiao 4\nXian Pudong 3\nQingdao Hongqiao 3\nQingdao Pudong 4\nQingdao Xuzhou 1\nXuzhou Hongqiao 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e10\n9\n8\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cbr /\u003e"}}]}