SP17402 DCEPC12J - Joy of Arbitrage

Description

Gitu is the smartest economist in the city. He has been kidnapped by Ankur and Vaibhav. They want him

Input Format

First line consists of T, the number of test cases. Each test case starts with an integer N, the different items to be sold and the different markets present. Next line contains N space separated integers, the units of each of the items Ankur and Vaibhav have. Each of the next N lines consists of N space separated integers. jth integer in ith line signifies the money earned after selling one unit of jth item in ith market.

Output Format

Output T lines corresponding to each test case, the maximum money that can be earned by following the process stated above.