// Arup Guha
// 2/25,28/2020
// Solution to COP 4516 Final Individual Contest Problem: Grading Bins

import java.util.*;

public class alarge {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<nC; loop++) {
		
			int n = stdin.nextInt();
			node myTrie = new node();
			
			// Add words to trie.
			for (int i=0; i<n; i++)
				myTrie.insert(stdin.next().toCharArray(), 0);
			
			// Do it!
			TreeSet<Integer> binSizes = myTrie.solve();
			
			// Note that the last bin size listed will always be n, but this isn't allowed.
			binSizes.pollLast();
			
			// Output the result.
			System.out.println(binSizes.size());
			while (binSizes.size() > 0)
				System.out.print(n/binSizes.pollLast()+" ");
			System.out.println();
		}
	}
}

class node {

	public boolean isWord;
	public int numWords;
	public node[] next;
	
	public node() {
		isWord = false;
		numWords = 0;
		next = new node[26];
	}
	
	public TreeSet<Integer> solve() {
		
		// Recursively solve each child.
		TreeSet[] kids = new TreeSet[26];
		Arrays.fill(kids, null);
		for (int i=0; i<26; i++)
			if (next[i] != null)
				kids[i] = next[i].solve();
			
		boolean isSet = false;
		TreeSet<Integer> possible = new TreeSet<Integer>();
		
		// This is tricky - if we are a word, then we CAN'T split into more bins due to the
		// prefix rule.
		if (!isWord) {
		
			// Go through each set of answers, taking all values that appear on all lists.
			for (int i=0; i<26; i++) {
			
				// Skip.
				if (next[i] == null) continue;
			
				// Make our initial set.
				if (!isSet) {
					for (Integer x: (TreeSet<Integer>)kids[i])
						possible.add(x);
					isSet = true;
				}
			
				// Do the and operation between the running set and this one.
				else {
				
					// Store new answer here.
					TreeSet<Integer> tmp = new TreeSet<Integer>();
					for (Integer x: (TreeSet<Integer>)kids[i])
						if (possible.contains(x))
							tmp.add(x);
					
					// Update set.
					possible = tmp;
				}
			}
		}
		
		// Add all the words in this bin as one group size as well.
		possible.add(numWords);
		return possible;
	}
	
	public void insert(char[] w, int k) {
		
		// This is true for all nodes down this path.
		numWords++;
		
		// End put the word here.
		if (k == w.length) {
			isWord = true;
			return;
		}
		
		// We need to create the path for this word.
		if (next[w[k]-'A'] == null) next[w[k]-'A'] = new node();
		
		// Recursively insert.
		next[w[k]-'A'].insert(w, k+1);
	}
}