Stock Charts

No attempts yetTime limit5sMemory limit512 MB

Problem

You are writing your newspaper's end of year economics summary, and you want charts that show how different stocks moved over the last year. You will show the prices of nn stocks, all measured at the same kk points of the year.

A simple chart for one stock draws line segments through the points (0,pricei,0)(0, price_{i,0}), (1,pricei,1)(1, price_{i,1}), \dots, (k1,pricei,k1)(k-1, price_{i,k-1}) in that order, where pricei,jprice_{i,j} is the price of stock ii at time point jj.

To save space you use an overlaid chart. An overlaid chart combines one or more simple charts and shows several stocks at once, one line per stock. So that no two stocks are confused, the lines inside one overlaid chart may not cross and may not touch.

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

Input

The first line contains a single integer TT, the number of test cases. 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]

The first line of a test case holds the number of stocks nn and the number of time points kk. The next nn lines hold one stock's prices in time order. Every pricei,jprice_{i,j} is an integer.

Limits

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

Output

For each test case print one line of the form Case #X: Y, where XX is the test case number starting at 1 and YY is the minimum number of overlaid charts needed to show every stock's prices.