cho.sh
Notes
Loading...

Caesar Cipher

Time limit

2s

Memory limit

256 MB

Problem

A Caesar cipher is a substitution cipher that replaces each character with the character a fixed number of positions later in a given alphabet order. After the end of the alphabet, the order wraps back to the beginning. For example, with the usual uppercase alphabet and a shift value of 3, A becomes D, B becomes E, and X becomes A. The number of positions moved is called the shift value.

You are given an alphabet order A, a plaintext word W, and an encrypted string S. A shift value x is possible if decrypting S with shift x makes W appear exactly once in the decrypted string. Find every possible shift value x where 0 <= x < |A|.

Input

The first line contains an integer N, the number of test cases. Each test case consists of three lines: the alphabet order A, the plaintext word W, and the encrypted string S, in that order.

A contains only lowercase letters, uppercase letters, and digits. Its order may be different from lexicographic order, and all characters in A are distinct.

The input ranges are 3 <= |A| <= 62, 1 <= |W| <= 50,000, and 3 <= |S| <= 500,000.

Output

For each test case, print one line.

If no shift value satisfies the condition, print no solution.

If exactly one shift value satisfies the condition, print unique: x, where x is that shift value.

If multiple shift values satisfy the condition, print ambiguous: followed by the valid shift values in increasing order, separated by spaces.