/* Tony Aguilar
 * BHCSI Final Competition Caeser's cipher problem
 */

import java.io.*;
import java.util.*;

public class caesar {
	public static void main(String[] args) throws IOException
	{
		Scanner in=new Scanner(new File("caesar.in"));
		int shift,n;		//Shift amount and number of words
		String word; 	//Words in the line to be encoded
		
		//Loop through the messages
		for(int i=in.nextInt(); i>0; i--)
		{
			shift=in.nextInt();	//Input the shift amount
			
			//Loop through all of the words in the message
			for(int j=in.nextInt(); j>0; j--)
			{
				word=in.next();	//Input word
				
				char[] arr=word.toCharArray();
				for(int k=0; k<arr.length; k++)
				{
					int value = (arr[k] - 'a' + shift)%26;
					arr[k] = (char)(value + 'a');	//Shift letters
				}
				System.out.print(new String(arr)+" ");
			}
			System.out.println("\n");
		}
	}
}
