Free Willy

No attempts yetTime limit5sMemory limit256 MB

Problem

Willy sits in a cage. The guard offers him his freedom if he solves a puzzle.

You are given two words of length NN and PP permutations that Willy may use. A permutation is written as a lowercase string that uses each of the first NN letters of the alphabet exactly once. Applying a permutation qq to a word ww produces a new word whose ii-th letter is the qiq_i-th letter of ww, where qiq_i is the alphabet position of the ii-th letter of qq. Count a as 1 and b as 2.

Applying the permutation bcdefaghi to the word KULTURUKE gives ULTURKUKE. The first six letters rotate one place to the left and the rest stay where they are.

Willy may use only the given permutations, and he may use the same permutation more than once. The cage opens if he turns the first word into the second word with at most LL applications. Find the smallest number of applications.

Input

The first line contains the number of test cases TT. (T30T \le 30)

The first line of each test case contains NN, PP, and LL, separated by spaces. (1N261 \le N \le 26, 1P101 \le P \le 10, 1L101 \le L \le 10)

The second line contains two words of length NN, separated by a space. Both words consist of English letters only.

Each of the next PP lines contains one allowed permutation, a string that uses each of the first NN lowercase letters of the alphabet exactly once.

Output

Print one line for each test case. Print the smallest number of applications needed to turn the first word into the second word, or whalemeat if it cannot be done with at most LL applications.