Stock Charts (Large)

No attempts yetTime limit5sMemory limit512 MB

Problem

You are writing your newspaper's end of year economics summary, and you want to include charts that show how several stocks moved over the past year. You will show the price of nn different stocks at the same kk points of the year.

A simple chart of one stock draws line segments through the points (0,price0)(0, price_0), (1,price1)(1, price_1), ..., (k1,pricek1)(k-1, price_{k-1}), where priceiprice_i is the price of that stock at the iith point in time.

To save space you combine several simple charts into one overlaid chart, which draws one line for each stock it contains. So that the stocks stay distinguishable, no two lines inside one overlaid chart may cross, and no two lines may touch.

Two lines neither cross nor touch exactly when one of the two stocks is strictly more expensive than the other at all kk points in time.

Given the prices of nn stocks at each of kk points in time, find the minimum number of overlaid charts needed to show every stock.

Input

The first line contains one integer TT, the number of test cases. Then TT test cases follow, each in this form:

n k
price_0,0 price_0,1 ... price_0,k-1
price_1,0 price_1,1 ... price_1,k-1
...
price_n-1,0 price_n-1,1 ... price_n-1,k-1

pricei,jprice_{i,j} is an integer, the price of the iith stock at time jj.

Limits

  • 1T1001 \le T \le 100
  • 1n1001 \le n \le 100
  • 2k252 \le k \le 25
  • 0pricei,j10000000 \le price_{i,j} \le 1000000

Output

For each test case, print one line Case #X: Y, where XX is the number of the test case starting from 1 and YY is the minimum number of overlaid charts needed to show the prices of all nn stocks.