// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
using namespace std;
// mylittledoge
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
for(int t =0; t < T; t++) {
int N,M;
cin >> N >> M;
vector<string> A(N);
vector<int> B(N);
for(int i =0; i < N; i++) cin >> A[i] >> B[i];
map<long long,long long> S;
vector<long long> hsh(1<<(M/2));
for(int a =0; a < (1<<(M/2)); a++) {
long long x =0;
bool ok =true;
for(int i =0; i < N; i++) {
int y =B[i];
for(int j =0; j < M/2; j++)
if((A[i][j] == '1') == ((a>>j)&1)) y--;
if(y < 0) ok =false;
x =x*(M+1)+y;}
if(!ok) x =-1;
hsh[a] =x;
S[x] +=1;}
int ans =-1;
long long ansP =0;
for(int a =0; a < (1<<(M-M/2)); a++) {
long long x =0;
for(int i =0; i < N; i++) {
int y =0;
for(int j =M/2; j < M; j++)
if((A[i][j] == '1') == ((a>>(j-M/2))&1)) y++;
x =x*(M+1)+y;}
ansP +=S[x];
if(ans == -1 && S[x] > 0) {
for(int i =0; i < (1<<(M/2)); i++)
if(x == hsh[i]) ans =i+(1<<(M/2))*a;
}
}
if(ansP != 1) cout << ansP << " solutions";
else for(int i =0; i < M; i++) cout << ((ans>>i)&1);
cout << "\n";}
return 0;}
// look at my code
// my code is amazing