# Importing necessary library
from io import StringIO
# Function to encrypt the message using Caesar Cipher
def caesar_cipher(message, key):
encrypted_message = ""
for char in message:
if char.isalpha():
if char.isupper():
encrypted_message += chr((ord(char) - 65 + key) % 26 + 65)
else:
encrypted_message += chr((ord(char) - 97 + key) % 26 + 97)
else:
encrypted_message += char
return encrypted_message
# Main function to read input and perform encryption
def main():
try:
output = StringIO()
n = int(input())
if n < 1 or n > 5:
print("Invalid Counter!")
return
for _ in range(n):
data = input().split()
if len(data) != 2:
print("Invalid Input!")
return
message, key = data
key = int(key)
if key < 1:
print("Invalid Input!")
return
result = caesar_cipher(message, key)
output.write(result + "\n")
print(output.getvalue().strip())
except ValueError:
print("Invalid Input!")
# Calling the main function
main()