Under construction

Still being built. Things may change

Spontaneous Trip

Time limit3sMemory limit256 MB

Summary
Given flight counts between airports, find the most likely airport reached after exactly K random flights starting from ICN.
Level

Medium5 of 10

Topics
Probability, Dynamic programming, Graph
Solved
No attempts yet

Problem

Sangil travels on impulse. One journey goes like this.

  1. He goes to the airport of the city he is in.
  2. He buys a ticket for one of the flights leaving that airport, picked at random. Every flight leaving the airport is equally likely.
  3. He boards that flight and lands in another city.

One trip consists of exactly KK 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 KK 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 KK journeys, find the last airport of the course with the highest probability. Such a course always exists.

Input

The first line contains the number of test cases TT (1≤T≤101 \le T \le 10).

The first line of each test case contains the number of airports NN and the number of journeys in one trip KK (2≤N≤1002 \le N \le 100, 1≤K≤10001 \le K \le 1000).

Each of the next NN 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 NN lines contains NN integers. The jj-th integer on the ii-th line, SijS_{ij}, is the number of flights that leave airport ii and land at airport jj (0≤Sij≤1000 \le S_{ij} \le 100, Sii=0S_{ii} = 0). Airport ii has Si1+Si2+⋯+SiNS_{i1} + S_{i2} + \dots + S_{iN} departing flights in total, so the probability that Sangil flies from airport ii to airport jj is SijS_{ij} divided by that sum.

Output

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.

Examples2

  1. Example 1

    Input
    1
    4 3
    ICN
    FUK
    PEK
    FNJ
    0 2 3 0
    2 0 3 0
    1 2 0 5
    0 0 5 0
    
    Expected output
    PEK
    
  2. Example 2

    Input
    3
    5 1
    ICN
    AAA
    BBB
    ZZZ
    QQQ
    0 3 2 0 0
    1 0 0 1 1
    0 0 0 1 0
    0 0 0 0 1
    1 0 0 0 0
    5 2
    ICN
    AAA
    BBB
    ZZZ
    QQQ
    0 3 2 0 0
    1 0 0 1 1
    0 0 0 1 0
    0 0 0 0 1
    1 0 0 0 0
    5 3
    ICN
    AAA
    BBB
    ZZZ
    QQQ
    0 3 2 0 0
    1 0 0 1 1
    0 0 0 1 0
    0 0 0 0 1
    1 0 0 0 0
    
    Expected output
    AAA
    ZZZ
    QQQ