// Arup Guha
// 11/18/2010
// Example of a polynomial time reduction from Vertex Cover to Subset Sum
// Included is a 2^n solution for Subset Sum.
import java.util.*;
import java.io.*;

public class vc {
	
	private int[][] adjmat;
	private byte k;
	private int numedges;
	
	// Set up the Vertex Cover object.
	// We assume that mat is symmetric, and has data about an undirected graph.
	public vc(int[][] mat, byte numverts) {
		adjmat = mat;
		k = numverts;
		numedges = countedges();
	}
	
	// Solve this Vertex Cover instance via a reduction to Subset Sum =)
	public boolean solve() {
		subsum convertedInstance = transform();
		return convertedInstance.solve();
	}
	
	// The constructor calls this to determine the number of edges.
	private int countedges() {
		
		// Just go through the matrix counting each unique edge.
		int edges = 0;
		for (int i=0; i<adjmat.length; i++)
			for (int j=i+1; j<adjmat.length; j++)
				if (adjmat[i][j] == 1)
					edges++;
					
		// Return this.
		return edges;
	}
	
	public subsum transform() {
		
		byte[][] numbers = new byte[adjmat.length+numedges][numedges+1];
		
		// Most entries will be zero, so let's fill everything in with zeros.
		for (int i=0; i<numbers.length; i++)
			for (int j=0; j<numbers[i].length; j++)
				numbers[i][j] = 0;
		
		// Fill in 1's for most significant digit for each vertex.
		for (int i=0; i<adjmat.length; i++)
			numbers[i][0] = 1;
			
		// Fill in the 1's for the "slack" variables.
		for (int i=adjmat.length; i<numbers.length; i++)
			numbers[i][i+1-adjmat.length] = 1;
			
		// Fill in each edge.
		int edgecount = 0;
		for (int i=0; i<adjmat.length; i++) {
			for (int j=i+1; j<adjmat.length; j++) {
				
				// We found an edge.
				if (adjmat[i][j] == 1) {
					edgecount++;
					
					// These are the two bits we need to set to 1.
					numbers[i][edgecount] = 1;
					numbers[j][edgecount] = 1;
				}
			}
		}
		
		// Now just fill in the target.
		byte[] target = new byte[numedges+1];
		
		target[0] = k;
		for (int i=1; i<target.length; i++)
			target[i] = 2;
			
		// Here is our Subset Sum instance!
		return new subsum(numbers, target,(byte)4);
	}
	
	public static void main(String[] args) throws Exception {
		
		Scanner fin = new Scanner(new File("vc.in"));
		
		int numCases = fin.nextInt();
		
		// Loop through all cases.
		for (int i=1; i<=numCases; i++) {
			
			// Get the number of vertices in the graph and k.
			int n = fin.nextInt();
			byte k = fin.nextByte();
			
			// Read in the graph.
			int[][] mat = new int[n][n];
			for (int r=0; r<n; r++)
				for (int c=0; c<n; c++)
					mat[r][c] = fin.nextInt();
					
			vc thisProblem = new vc(mat, k);
			
			// Solve this problem.
			if (thisProblem.solve())
				System.out.println("Case "+i+": YES");
			else
				System.out.println("Case "+i+": NO");
			
		}
		
		fin.close();
	}
}