// Arup Guha
// 9/20/2016
// Implements DFS and BFS using an Adjacency List (efficient graph storage)

/*** Input Format
 *
 *   Line 1 - n, number of graphs
 *   First Line of each graph: 2 space separated ints: v and e, number of vertices and edges in the graph
 *   The next e lines contain a pair of integers, i and j, 1 <= i, j <= v, i!= j specifying the vertices
 *   connected by the edge. Edges are undirected.
 *
 *   Output Format - a sorted list (largest to smallest) of the sizes of each component
 *
 ***/
 
 import java.util.*;
 
 public class dfsbfs {
 	
 	 // Set to true if you want the BFS printing distances to each vertex from source each time it runs.
 	 final public static boolean PRINTDIST = true;
 	
 	 public static ArrayList[] graph;
 	 public static int numVertices;
 	 public static int numEdges;
 	 
     public static void main(String[] args) {
     	
     	 Scanner stdin = new Scanner(System.in);
     	 int numCases = stdin.nextInt();
     	 
     	 // Process each input graph.
     	 for (int loop=0; loop<numCases; loop++) {
     	 	
     	 	 // Read in vertices and edges.
     	 	 numVertices = stdin.nextInt();
     	 	 numEdges = stdin.nextInt();
     	 	 
     	 	 // First set up the array, then set up all the empty array lists.
     	 	 // graph[i] will store each vertex i is connected to.
     	 	 graph = new ArrayList[numVertices];
     	 	 for (int i=0; i<numVertices; i++)
     	 	 	 graph[i] = new ArrayList<Integer>();
     	 	 	
     	 	 // Now read through the edges.
     	 	 for (int i=0; i<numEdges; i++) {
     	 	 	 
     	 	 	 // Don't forget to subtract 1!
     	 	 	 int v1 = stdin.nextInt()-1;
     	 	 	 int v2 = stdin.nextInt()-1;
     	 	 	 
     	 	 	 // This is important - add the edge "both" ways.
     	 	 	 graph[v1].add(v2);
     	 	 	 graph[v2].add(v1);
     	 	 }
     	 	 
     	 	 // Will store each component size here.
     	 	 ArrayList<Integer> componentSizes = new ArrayList<Integer>();
     	 	 boolean[] visited = new boolean[numVertices];
     	 	 
     	 	 // Go through each vertex, searching from each unvisited one.
     	 	 for (int i=0; i<numVertices; i++) {
     	 	 	 
     	 	 	 // i is in a new component.
     	 	 	 if (!visited[i]) {
     	 	 	 	
     	 	 	 	 // Run a DFS (or you can put in the BFS) from i.
     	 	 	 	 int size = bfs(i, visited);
     	 	 	 	 
     	 	 	 	 // Add in this component size.
     	 	 	 	 componentSizes.add(size);
     	 	 	 }
     	 	 }
     	 	 
     	 	 // Sort and reverse.
     	 	 Collections.sort(componentSizes);
     	 	 Collections.reverse(componentSizes);
     	 	 	
     	 	 // Print the output for this case.
     	 	 for (int i=0; i<componentSizes.size()-1; i++)
     	 	 	 System.out.print(componentSizes.get(i)+" ");
     	 	 System.out.println(componentSizes.get(componentSizes.size()-1));
     	 }
     }
     
     public static int dfs(int v, boolean[] visited) {
     	
     	 // Mark v as visited.
     	 int res = 1;
     	 visited[v] = true;
     	 
     	 // Recursively visit all unvisited neighbors, adding sizes of each recursive call.
     	 for (Integer next : (ArrayList<Integer>)graph[v])
     	 	 if (!visited[next])
     	 	 	 res += dfs(next, visited);
     	 	 	 
     	 // This is the # of vertices visited for this search.
     	 return res;
     }
     
     public static int bfs(int v, boolean[] visited) {
     	
     	 // Need a queue for a BFS.
     	 LinkedList<Integer> q = new LinkedList<Integer>();
     	 
     	 // Initialize search.
     	 q.offer(v);
     	 visited[v] = true;
     	 int res = 0;
     	 
     	 // Stores all distances from v to other vertices.
     	 int[] dist = new int[numVertices];
     	 Arrays.fill(dist, -1);
     	 dist[v] = 0;
     	 
     	 // Run till the queue is empty.
     	 while (q.size() > 0) {
     	 	
     	 	 // Get next item from queue.
     	 	 int cur = q.poll();
     	 	 res++;
     	 	 
     	 	 // Go through all unvisited neighbors and enqueue.
     	 	 for (Integer next : (ArrayList<Integer>)graph[cur]) {
     	 	 
     	 	 	 // It's VERY IMPORTANT to mark as visited now!!!
     	 	 	 if (!visited[next]) {
     	 	 	 	 q.offer(next);
     	 	 	 	 visited[next] = true;
     	 	 	 	 
     	 	 	 	 // The distance to next is just 1 more than to cur, where we came form.
     	 	 	 	 dist[next] = dist[cur] + 1;
     	 	 	 }
     	 	 }
     	 }
     	 
     	 // See BFS's distance calculation.
     	 if (PRINTDIST) {
     	 	 System.out.println("Starting vertex is "+(v+1));
     	 	 for (int i=0; i<numVertices; i++) 
     	 	 	 if (dist[i] != -1) 
     	 	 	 	 System.out.println("Distance to vertex "+(i+1)+" = "+dist[i]);
     	 	 System.out.println("-----------------------------");
     	 }
     	 
     	 // Here is our answer.
     	 return res;
     }	
 }