#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#define MAX_CIPHER 500
#define MAX_CRIB 10
#define GROUP_PER_LINE 10
#define CHAR_PER_GROUP 5

void read_cipher(char *cipher, int n)
{
  int i, c;

  for (i = 0; i < n; i++) {
    if (i && !(i % CHAR_PER_GROUP)) {
      /* read extra space or '\n' */
      c = getchar();
      if (!(i % (CHAR_PER_GROUP * GROUP_PER_LINE))) {
	assert(c == '\n');
      } else {
	assert(c == ' ');
      }
    }
    c = getchar();
    cipher[i] = c;
  }
  cipher[n] = 0;
}

void decrypt(int n, int s, int m, char *cipher, char *plain)
{
  int i, j;
  char t;

  plain[n] = 0;

  /* first undo the substitution */
  for (i = 0; i < n; i++) {
    plain[i] = ((cipher[i] - 'A') + (26 - s)) % 26 + 'A';
  }

  /* then undo the reverse */
  for (i = 0; i+m < n; i += m) {
    for (j = 0; j < m/2; j++) {
      t = plain[i+j];
      plain[i+j] = plain[i+m-1-j];
      plain[i+m-1-j] = t;
    }
  }
  for (j = 0; j < (n-i)/2; j++) {
    t = plain[i+j];
    plain[i+j] = plain[n-1-j];
    plain[n-1-j] = t;
  }
}

int main(void)
{
  char cipher[MAX_CIPHER+1], plain[MAX_CIPHER+1];
  char crib[MAX_CRIB+1];
  int i, k, n, s, m, found;


  scanf("%d\n", &k);

  for (i = 0; i < k; i++) {
    scanf("%d\n", &n);
    read_cipher(cipher, n);
    scanf("%s\n", crib);

    found = 0;
    for (s = 1; s < 26 && !found; s++) {
      for (m = 5; m <= 20 && !found; m++) {
	decrypt(n, s, m, cipher, plain);
	if (strstr(plain, crib)) {
	  printf("%d %d\n", s, m);
	  found = 1;
	}
      }
    }
    if (!found) {
      printf("Crib is not encrypted.\n");
    }
  }
  return 0;
}

