import java.io.*;
import java.lang.*;
import java.util.*;

public class H_h {
    
    public static final int MAX_CIPHER = 500;
    public static final int MAX_CRIB = 10;
    public static final int GROUP_PER_LINE = 10;
    public static final int CHAR_PER_GROUP = 5;
    public static DataInputStream in = new DataInputStream(System.in);

    static String read_cipher(int n) throws IOException {
	StringBuffer result = new StringBuffer("");
	String line;
	int num_lines, i;

	num_lines = n / (GROUP_PER_LINE*CHAR_PER_GROUP);
	if (n % (GROUP_PER_LINE * CHAR_PER_GROUP) != 0) {
	    num_lines++;
	}
	for (i = 0; i < num_lines; i++) {
	    line = in.readLine();
	    StringTokenizer str = new StringTokenizer(line);
	    while (str.hasMoreTokens()) {
		result.append(str.nextToken());
	    }
	}
	
	return result.toString();
    }

    static String decrypt(int n, int s, int m, String cipher) {
	StringBuffer result = new StringBuffer(cipher);
	int i, j;

	/* do the reverse */
	/*
	for (i = 0; i+m < n; i += m) {
	    result.append(new StringBuffer(cipher.substring(i, i+m)).reverse());
	}
	if (i + m >= n) {
	    result.append(new StringBuffer(cipher.substring(i, n)).reverse());
	}
	*/

	for (i = 0; i+m < n; i += m) {
	    for (j = 0; j < m/2; j++) {
		char t = result.charAt(i+j);
		result.setCharAt(i+j, result.charAt(i+m-1-j));
		result.setCharAt(i+m-1-j, t);
	    }
	}
	for (j = 0; j < (n-i)/2; j++) {
	    char t = result.charAt(i+j);
	    result.setCharAt(i+j, result.charAt(n-1-j));
	    result.setCharAt(n-1-j, t);
	}
			      

	/* do the substitution */
	for (i = 0; i < n; i++) {
	    result.setCharAt(i, (char)(((result.charAt(i) - 'A') + (26-s)) % 26 + 'A'));
	}

	return result.toString();
    }

    public static void main(String[] args) {
	try {
	    String line, crib, cipher, plain;
	    int i, k, n, s, m;
	    boolean found;

	    line = in.readLine();
	    k = Integer.parseInt(line);
	    for (i = 0; i < k; i++) {
		n = Integer.parseInt(in.readLine());
		cipher = read_cipher(n);
		crib = in.readLine();

		found = false;
		for (s = 1; s <= 25 && !found; s++) {
		    for (m = 5; m <= 20 && !found; m++) {
			plain = decrypt(n, s, m, cipher);
			if (plain.indexOf(crib) >= 0) {
			    found = true;
			    System.out.println(s + " " + m);
			}
		    }
		}
		if (!found) {
		    System.out.println("Crib is not encrypted.");
		}
	    }
	} catch (IOException e) {
	}
    }

}
