Some pies are sweet, full of fruit and jam and sugar.
Some pies are savory, full of meat and potatoes and spices.
Some pies are in fact not pies at all but tarts or galettes. This probably won't stop you from eating them.
Every single day for N days, you're determined to eat a pie for dinner. Every morning, you'll take a trip to your local pie shop, and buy 0 or more of their pies. Every night, you'll eat one pie that you've bought. Pies never go bad, so you don't need to eat a pie on the same day that you bought it. You may instead eat one that you purchased on an earlier day.
On the ith day, the shop has M pies for sale, with the jth of these pies costing Ci,j dollars. You can choose to buy any (possibly empty) subset of them. However, this shop has measures in place to protect itself against crazy pie fanatics buying out its products too quickly. In particular, if you buy p pies on a single day, you must pay an additional tax of p2 dollars.
Input begins with an integer T, the number of times you go on a pie-eating spree. For each case, there is first a line containing two space-separated integers, N and M. Then, N lines follow, each containing M space-separated integers. The jth integer on the ith line is Ci,j.
For the ith case, print a line containing "Case #i: " followed by the minimum you need to pay to eat a pie every day.
1 ≤ T ≤ 100
1 ≤ N, M ≤ 300
1 ≤ Ci,j ≤ 1,000,000
In the first case, you should buy both pies on the first day, for a total cost of 1 + 1 + 22 = 6. On the second day you should buy one pie for 100 + 12 = 101. On the third day you can eat one of the spare pies you bought on the first day.
In the third case, you should buy and eat the cheapest pie every day, for a daily cost of 1 + 12 = 2, and a total cost of 10.
In the fourth case, one possible solution is to buy two pies on the first day (1 + 1 + 22 = 6), two pies on the second day (2 + 2 + 22 = 8), and one pie on the third day (3 + 12 = 4) for a total cost of 18. On the fourth and fifth days you can eat your two spare pies from the first and second days.