Given flight counts between airports, find the most likely airport reached after exactly K random flights starting from ICN.
Medium5ProbabilityDynamic programmingGraphNo attempts yetTime limit3sMemory limit256 MBSangil travels on impulse. One journey goes like this.
One trip consists of exactly K journeys, and it always starts at the airport ICN. Some airports have no departing flight at all, so a trip that reaches one of them cannot continue.
A course is the sequence of airports Sangil passes through during the K journeys. The probability of a course is the product of the probabilities of the flights picked in each journey. Among the courses that finish all K journeys, find the last airport of the course with the highest probability. Such a course always exists.
The first line contains the number of test cases T (1≤T≤10).
The first line of each test case contains the number of airports N and the number of journeys in one trip K (2≤N≤100, 1≤K≤1000).
Each of the next N lines contains the IATA code of one airport. A code consists of three uppercase letters, the codes are pairwise different, and one of them is ICN.
Each of the next N lines contains N integers. The j-th integer on the i-th line, Sij, is the number of flights that leave airport i and land at airport j (0≤Sij≤100, Sii=0). Airport i has Si1+Si2+⋯+SiN departing flights in total, so the probability that Sangil flies from airport i to airport j is Sij divided by that sum.
For each test case, print the IATA code of the last airport of the most likely course on its own line. If several most likely courses end at different airports, print the code that comes first in alphabetical order.