The cryptographer Borge is writing a new security module for his company. Nobody could read his code in the previous module and it caused a lot of trouble, so his boss told him to keep this one much simpler.
The secret key c is a one to one map from the 26 uppercase letters onto the 26 uppercase letters. For a string S=s1s2…sm the module computes crypt(S)=c(s1)c(s2)…c(sm), and the decryption key c−1 satisfies c−1(c(s))=s.
The scheme has a weakness. For some q the identity cryptq(crypt(S))=S holds, so an attacker only has to keep encrypting the ciphertext until readable text appears. A small q is dangerous, so Borge needs q first.
You are given a plaintext S and the matching ciphertext T=crypt(S). Here q is the smallest non-negative integer such that applying crypt to T another q times gives S back.
The pair S and T reveals the value of c only on the letters that occur in S, and the images of the other letters stay unknown. If every key c that agrees with S and T gives the same q, print that value. If the value of q depends on the key, print mjau.
The first line has the number of test cases n (1≤n≤100). Each test case consists of two lines, the plaintext S on the first line and the ciphertext T on the second. At least one key satisfies crypt(S)=T. Both strings use only the uppercase letters 'A' to 'Z', and 1≤∣S∣=∣T∣≤1000. The encryption function c is different in each test case.
For each test case print q on its own line. If S and T alone do not determine q, print mjau.