// Arup Guha
// Solution to UF Contest Question: Rides
// 1/30/2010

import java.util.Scanner;

public class rides {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		
		int numCases = stdin.nextInt();
		
		for (int i=0; i<numCases; i++) {
			
			int numRides = stdin.nextInt();
			int numBridges = stdin.nextInt();
			
			// Fill in our data structures to solve the problem
			String[] rides = new String[numRides];
			int[][] adj = new int[numRides][numRides];
			for (int k=0; k<numRides; k++)
				for (int j=0; j<numRides; j++)
					adj[k][j] = 0;
			
			int rideNum = makeGraph(adj, rides, numBridges, stdin);

			// Answer the simple cases.
			if (numRides == 1)
				System.out.println("Yes");
			else if (rideNum < numRides)
				System.out.println("No");
				
			// Normal case.
			else {
			
				if (connected(adj))
					System.out.println("Yes");
				else
					System.out.println("No");
				
			}
		} // end for-numCases
	}
	
	public static int makeGraph(int[][] graph, String[] rides, int numBridges, Scanner stdin) {
		
		// Initial ride number.
		int rideNum = 0;
		
		for (int j=0; j<numBridges; j++) {
			
			// Get the two rides connected by a bridge.
			String ride1 = stdin.next();
			String ride2 = stdin.next();
				
			// Look up the number of ride1, or create it.
			int index1 = getIndex(rides, ride1, rideNum);
			
			// This was created, so we need to add it to our list of ride names.
			if (index1 == rideNum) {
				rides[index1] = ride1;
				rideNum++;
			}
				
			// Do the same for ride 2.
			int index2 = getIndex(rides, ride2, rideNum);
			if (index2 == rideNum) {
				rides[index2] = ride2;
				rideNum++;
			}
				
			// Put in an edge in our graph between these two.
			graph[index1][index2] = 1;
			graph[index2][index1] = 1;
				
		} // end-for
		
		return rideNum;
	}
	
	// Returns the index in rides in which ride is stored. numRides represents
	// the number of strings store in rides. If ride isn't stored, numRides is
	// returned.
	public static int getIndex(String[] rides, String ride, int numRides) {
		
		// Try to find ride.
		for (int i=0; i<numRides; i++)
			if (rides[i].compareTo(ride) == 0)
				return i;
				
		// Never found it so we return the first "new" index.
		return numRides;
	}
	
	// Returns true iff the graph stored in adj is connected.
	public static boolean connected(int[][] adj) {
		
		// Will keep track of where we've been.
		boolean[] visited = new boolean[adj.length];
		for (int k=0; k<visited.length; k++)
			visited[k] = false;
				
		// Run our dfs from the first node.	
		dfs(adj, visited, 0);
				
		// See if any node hasn't been visited.
		for (int k=0; k<visited.length; k++) 
			if (!visited[k]) 
				return false;
					
		// If we get here, then every node is connected.	
		return true;
	}
	
	// Runs a depth-first search of the graph stored in adj from node.
	// visited keeps track of where we've been.
	public static void dfs(int[][] adj, boolean[] visited, int node) {
		
		visited[node] = true;
		for (int i=0; i<adj.length; i++)
			if (!visited[i] && adj[i][node] == 1)
				dfs(adj, visited, i);
		
	}
}