// Arup Guha
// 3/5/2019
// Solution to 2019 Mercer Programming Contest Problem 5: Finding Frequently Planted Motif

import java.util.*;

public class motif {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<numCases; loop++) {
			
			String s = stdin.next();
			int freq = stdin.nextInt();
			int len = stdin.nextInt();
			int maxd = stdin.nextInt();
			
			// Just copy these in, runtime is O(n^2).
			String[] all = new String[s.length()-len+1];
			for (int i=0; i<all.length; i++)
				all[i] = s.substring(i, i+len);
			
			// Store all the ones we'll print here.
			HashSet<String> printed = new HashSet<String>();
			
			// Dumb - they didn't listen to their own problem statement. There is no
			// space after the last word...
			boolean flag = false;
			
			// Just try them all.
			for (int i=0; i<all.length; i++) {
				
				// Did this already.
				if (printed.contains(all[i])) continue;
				
				// Count matches.
				int cnt = 1, prevMatch = -5000;
				for (int j=0; j<all.length; j++) {
					if (dist(all[i], all[j]) <= maxd && (j-prevMatch >= len) && Math.abs(i-j) >= len) {
						cnt++;
						prevMatch = j;
					}
				}
				
				// Print and add.
				if (cnt >= freq) {
					if (flag) System.out.print(" ");
					System.out.print(all[i]);
					flag = true;
					printed.add(all[i]);
				}
			}
			
			// Get the first line out.
			if (printed.size() == 0)
				System.out.println("No motif found");
			else
				System.out.println();
			
			// The blank line.
			System.out.println();
		}
	}
	
	// Assumes len(a) = len(b).
	public static int dist(String a, String b) {
		int res = 0;
		for (int i=0; i<a.length(); i++)
			if (a.charAt(i) != b.charAt(i))
				res++;
		return res;
	}

}
