This page is still under construction.

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

Key to Knowledge

Time limit10sMemory limit256 MB

Summary
Reconstruct the true-or-false key of up to 30 questions from each student's answers and score, printing the unique key or the count of matching keys.
Level

Medium7 of 10

Topics
Backtracking, Brute force, Bit manipulation
Solved
No attempts yet

Problem

A while ago a class of students took an exam. Every question was true or false, and the questions were hard. Even afterward, with the textbook, the lecture notes and each other to work from, the students are not sure what all the correct answers were. They could ask the professor, but he is not the kind of person you would disturb with a question that gives away your ignorance. The students do at least remember exactly how they answered.

The professor has handed the exams back, and the results are not what anyone expected. He did not mark which answers were right or wrong. He wrote only the number of correct answers at the top of each paper. So what did the professor count as correct? Some of the grades are so far from what the students expected that a few of them suspect the professor miscounted.

Given the answers each student gave and the number of answers each student got right, work out the answer key that matches all of the results.

Input

The first line holds one positive integer, the number of test cases, at most 100. Each test case is given as follows.

  • One line with two space separated integers nn and mm (1≤n≤121 \le n \le 12, 1≤m≤301 \le m \le 30): the number of students and the number of questions on the exam.
  • nn lines, one per student. Each line holds mm digits, each digit either 0 or 1, the answers that student gave, where 0 means false and 1 means true. A single space follows, then an integer cc (0≤c≤m0 \le c \le m), the number of questions that student got right.

Output

Print one line per test case.

  • If exactly one answer key accounts for all of the results, print that key as mm digits, each one either 0 or 1.
  • Otherwise print how many answer keys account for all of the results, then a single space, then the word solutions. When no key works at all, the line reads 0 solutions.

Examples2

  1. Example 1

    Input
    3
    3 5
    01101 4
    10100 3
    00011 3
    3 5
    01101 0
    10100 3
    00011 2
    4 4
    0000 2
    1010 2
    0101 2
    1111 2
    
    Expected output
    00101
    0 solutions
    4 solutions
    
  2. Example 2

    Input
    4
    1 2
    00 1
    1 2
    01 1
    2 3
    000 2
    111 1
    1 4
    1010 2
    
    Expected output
    2 solutions
    2 solutions
    3 solutions
    6 solutions