public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int nSet = Integer.parseInt(line.trim());
			for (int i = 0; i < nSet; i++) {
				int nWords = Integer.parseInt(in.readLine().trim());
				String[] words = new String[nWords];
				for (int j = 0; j < words.length; j++)
					words[j] = in.readLine().trim();
				int ans = 0;
				for (int j = 0; j < words.length; j++)
					for (int k = j + 1; k < words.length; k++)
						ans = Math.max(check(words[j], words[k]), ans);
				out.append(ans + "\n");
			}
		}
		System.out.print(out);
	}