This page is still under construction.

Parts of this page are still being built. What you see may change.

Division Game

Time limit1sMemory limit128 MB

Summary
Decide whether the first player wins a game that divides chosen entries of one matrix row per move.
Level

Medium7 of 10

Topics
Game theory, Number theory, Math
Solved
No attempts yet

Problem

Division game is a game for two players. The board is an N×MN \times M matrix of positive integers.

The players move in turns. The player to move first picks one row. If every entry of that row is 1, that player loses. Otherwise the player picks at least one entry greater than 1 from that row and divides each picked entry by one of its own divisors other than 1. Different entries may use different divisors. For example, 6 can be divided by 2, 3 and 6, but it cannot be divided by 1, 4 or 5.

The player who first turns every entry of the matrix into 1 wins. In other words, the player who is handed a matrix of all 1s loses.

Both players play as well as they can. Given the matrix, decide whether the first player wins.

Input

The first line has the number of test cases TT, a positive integer at most 100000100000.

The first line of each test case has the number of rows NN and the number of columns MM, both between 11 and 5050 inclusive. Each of the next NN lines has MM integers, and every one of those integers is between 22 and 1000010000 inclusive.

Output

For each test case, print one line holding Case #x: YES or Case #x: NO, where xx is the test case number starting from 1. Print YES when the first player has a winning strategy and NO when the first player does not.

Examples2

  1. Example 1

    Input
    5
    2 2
    2 3
    2 3
    2 2
    4 9
    8 5
    3 3
    2 3 5
    3 9 2
    8 8 3
    3 3
    3 4 5
    4 5 6
    5 6 7
    2 3
    4 5 6
    7 8 9
    
    Expected output
    Case #1: NO
    Case #2: NO
    Case #3: NO
    Case #4: YES
    Case #5: YES
    
  2. Example 2

    Input
    1
    1 1
    2
    
    Expected output
    Case #1: YES