Under construction

Still being built. Things may change

Charging Chaos (Small)

Time limit5sMemory limit512 MB

Summary
Find the fewest bit positions to flip so the outlet strings match the device strings after reordering.
Level

Medium4 of 10

Topics
Brute force, Bit manipulation, Hash map
Solved
No attempts yet

Problem

Shota the farmer has just moved into his newly built farmhouse, and the outlets are not configured for his devices. Being a modern farmer, Shota owns several smartphones and laptops, and even a tablet for his favorite cow Wagyu. He owns NN devices in total.

The devices have different specifications and come from different companies, so each one needs a different electric flow to charge. Each outlet in the house also puts out one specific electric flow. An electric flow is a string of 0s and 1s of length LL.

Shota wants to charge all NN devices at the same time. His new house has exactly NN outlets. A master control panel with LL switches configures the flow from the outlets. Pressing switch ii flips the iith bit of the electric flow of every outlet in the house. For example, suppose the outlets put out these flows:

Outlet 0: 10
Outlet 1: 01
Outlet 2: 11

Pressing the second switch reconfigures them to:

Outlet 0: 11
Outlet 1: 00
Outlet 2: 10

If Shota has a smartphone that needs the flow 11, a tablet that needs 10, and a laptop that needs 00, then pressing the second switch charges all three.

Misaki is hired to sort this out. She has measured the flow of every outlet in the house and found that no two outlets put out the same flow. Decide whether Shota can charge all of his devices at the same time, and if he can, find the smallest number of switches that has to be pressed. The switches are big and heavy, so Misaki presses only as many as she needs.

Devices and outlets can be paired in any order.

Input

The first line contains the number of test cases TT. TT test cases follow. Each test case takes three lines. The first line contains two integers NN and LL separated by a space. The second line contains NN strings of length LL, separated by spaces, giving the initial electric flow of the outlets. The third line contains NN strings of length LL, in the same format, giving the electric flow each device needs.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤N≤101 \le N \le 10
  • 2≤L≤102 \le L \le 10
  • No two outlets put out the same flow initially.
  • No two devices need the same flow.

Output

For each test case, print one line in the form Case #x: y. Here xx is the test case number, starting at 1, and yy is the smallest number of switches that has to be pressed so Shota charges every device. If no set of switches works, print NOT POSSIBLE in place of yy, without the quotes. The spelling, the capital letters, and the single space have to match exactly.

Note

In the first test case of the first example, Misaki presses the second switch once. The flows become:

Outlet 0: 00
Outlet 1: 10
Outlet 2: 11

Shota then charges device 1 from outlet 0, device 2 from outlet 1, and device 0 from outlet 2. Fewer than one press cannot charge all three devices.

Examples1

  1. Example 1

    Input
    3
    3 2
    01 11 10
    11 00 10
    2 3
    101 111
    010 001
    2 2
    01 10
    10 01
    
    Expected output
    Case #1: 1
    Case #2: NOT POSSIBLE
    Case #3: 0