#include <iostream>
#include <string.h>
using namespace std;

void shiftby1(char s[], int n)
//
// shift every character in array <s> by 1
//
{
	for(int i=0; i<n; i++)
		s[i] = (s[i] == 'A' ? 'Z' : (char)(s[i]-1));
}

void reverse(char s[], int r, int size)
//
// reverse each group of <r> characters in array <s>
//
{
	int start;
	for(start = 0; start+r<=size; start += r) {
		for(int i=0; i<r/2; i++) {
			char temp = s[start+i];
			s[start+i] = s[start+r-i-1];
			s[start+r-i-1] = temp;
		}
	}
	r = size-start;
	for(int i=0; i<r/2; i++) {			// reverse the remainder
		char temp = s[start+i];
		s[start+i] = s[start+r-i-1];
		s[start+r-i-1] = temp;
	}
}

int main()
{
	int k;
	cin >> k;
	for(int cases = 1; cases<=k; cases++) {
		char string[501];
		int n;

		cin >> n;
		for(int i=0; i<n; i++)
			cin >> string[i];
		string[n] = '\0';

		char crib[11];
		cin >> crib;

		bool found = false;
		for(int shift=1; shift<26; shift++) {
			shiftby1(string, n);
			char string2[501];
			for(int r=5; r<=20; r++) {
				strcpy(string2, string);
				reverse(string2, r, n);
				if (strstr(string2, crib)) {
					cout << shift << ' ' << r << endl;
					found = true;
					break;
				}
			}
			if (found)
				break;
		}
		if (!found)
			cout << "Crib is not encrypted." << endl;
	}
	return 0;
}
