public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		fillSizes();
		Edmons_karp f;
		int source = 0, target = 37;
		int nTest = Integer.parseInt(in.readLine().trim());
		for (int i = 0; i < nTest; i++) {
			int[] nm = readInts(in.readLine());
			int n = nm[0], m = nm[1];
			f = new Edmons_karp(38);
			for (int vol = 1; vol <= m; vol++) {
				String[] s = in.readLine().trim().split(" ");
				f.g[source][vol] = 1;
				f.ady[source].add(vol);
				f.ady[vol].add(source);
				for (int k = 0; k < s.length; k++) {
					int size = sizes.get(s[k]);
					f.g[vol][size] = 1;
					f.ady[vol].add(size);
					f.ady[size].add(vol);
					if (f.g[size][target] == 0) {
						f.ady[size].add(target);
						f.ady[target].add(size);
					}
					f.g[size][target] = n / 6;
				}
			}
			int maxFlow = f.edmons_karp(source, target);
			out.append(maxFlow == m ? "YES\n" : "NO\n");
		}
		System.out.print(out);
	}