//Problem H - Double Trouble

#include <iostream>
#include <string.h>

using namespace std;

//reverse every m letters in A
void ReverseWords(char * A, int m, int n)
{
	int i,j;
	char temp[21];

	i=0;
	while(i<n)
	{
		if(i+m<=n)
		{
			for(j=0;j<m;j++)
				temp[j]=A[i+j];
			for(j=0;j<m;j++)
				A[i+m-1-j]=temp[j];
		}
		else //tail of A
		{
			j=0;
			while(i+j<n)
			{
				temp[j]=A[i+j];
				j++;
			}
			j--;
			for(j;j>=0;j--)
			{
				A[i]=temp[j];
				i++;
			}
		}
		i+=m;
	}
}


int main()
{
	char ctext[501],shift[501],reverse[501];;
	char crib[11];
	int j,k,n,s,r,i,found,bests,bestr;
	char c;

	cin>>k;
	for(j=0;j<k;j++){
	cin>>n;

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

		cin>>crib;

		found=0;

		//try all reversals
		for(r=5;r<21;r++)
		{
			strcpy(reverse,ctext);
			ReverseWords(reverse,r,n);
			//try all shifts
			for(s=25;s>0;s--)
			{
				strcpy(shift,reverse);
				//shift shift[] by s
				for(i=0;i<n;i++)
				{
					c = shift[i];
					c = (char)((c-'A'+s)%26 +'A');
					shift[i] = c;
				}
				//see if crib is a substring
				if(strstr(shift,crib))
				    if(!found)
					{
						found=1;
						bests=26-s; bestr=r;
					}
					else 
						if(bests>26-s){
							bests=26-s; bestr=r;
						}
			}
		}
		if(!found)
			cout<<"Crib is not encrypted."<<endl;
		else
			cout<<bests<<' '<<bestr<<endl;
	}
	}
	return 0;
}
				
