Lawnmower (Small)

Decide if row and column cuts of a mower that only lowers grass can produce the given target heights from a uniform lawn.

Medium4GreedyMatrixInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Alice and Bob have a lawn in front of their house, an NN metre by MM metre rectangle divided into 1m x 1m squares. Every square starts with grass 100 millimetres high.

Their new lawnmower has a height setting. Set it to any integer height hh between 1 and 100 millimetres and it cuts every square it passes over whose grass is higher than hh down to height hh, leaving squares that are already at most hh untouched. You run it by entering the lawn at any point on its edge; the mower then goes in a straight line perpendicular to that edge, cutting a swath 1 metre wide, until it exits on the other side. One run therefore cuts exactly one whole row or one whole column. The height can be changed only while the mower is off the lawn, so a single run uses a single height, but you may make as many runs as you want, in any order, at any heights.

You are given a pattern that states the desired height of the grass on every square. Decide whether some sequence of runs turns the lawn into exactly that pattern.

Input

The first line holds the number of test cases TT. Each test case begins with a line holding two integers NN and MM. The next NN lines follow, and the ii-th of them holds MM integers ai,ja_{i,j}, the desired height of the grass on the jj-th square of the ii-th row.

Limits

  • 1T1001 \le T \le 100
  • 1N,M101 \le N, M \le 10
  • 1ai,j21 \le a_{i,j} \le 2

Output

For each test case, print one line in the form Case #x: y, where xx is the case number starting from 1 and yy is YES if the pattern can be produced with the lawnmower and NO if it cannot.