At this moment, you are not allowed access to the question.

Available Marks: 7

Two words are called isomorphs (or more accurately, form an isomorphic pair) if they have the same length and the same pattern of repeated letters. The letters don't need to match between the words, only the positions where the repetitions occur. Isomorphs are of interest because one could be converted to the other using a simple substitution cipher.

Consider the words estate and tenant. In both cases the first letter is repeated five places later, and the third letter two places later. Letters in the other positions are not repeated. Define a repetition pattern to be an ordered list of relative positions where each letter is next repeated, with 0 indicating no repetition and a + preceding the repetitions for better readability. Thus both words have the repetition pattern

+5 0 +2 0 0 0
The same rules apply even if a letter occurs more than twice, so the words cannon and kisses have the pattern
0 0 +1 +2 0 0
People who like wordplay look for isomorphic pairs that form an incongruous phrase, like dysfunctional ventriloquism, but that level of semantic analysis is beyond even ProgComp entrants.

Your task

Write a program that identifies whether pairs of words are ismorphs. Input consists of the number of pairs on the first line (maximum 20), and then each pair on subsequent lines, separated by a space. Words are between 1 and 20 letters long, all lower-case, no punctuation.

For each pair, your program should list the two words and classify them as either

Example

6
secret cowboy
yummy tweet
exponential amputations
reflective programmer
financial turnaround
cutthroat communism
produces...
secret, cowboy are isomorphs with repetition pattern 0 +3 0 0 0 0
yummy, tweet are isomorphs with repetition pattern +4 0 +1 0 0
exponential, amputations are isomorphs with repetition pattern +5 0 0 0 +2 0 0 0 0 0 0
reflective, programmer are not isomorphs
financial, turnaround have different lengths
cutthroat, communism are isomorphs with repetition pattern 0 0 +1 +5 0 0 0 0 0

Test data

Test your program using the following input.

20
all inn
doll door
level kayak
squeaky sunlamp
gutless sheriff
trapdoor flywheel
mistiest monsoons
throwaway hepatitis
explosive magnesium
wealthiest subterfuge
kookaburra toothbrush
sportswomen spokeswoman
tightfisted hitchhikers
cryptography manipulation
sharpshooter marshmallows
ambidextrous thunderclaps
incompatible housewarming
sportsmanlike environments
disfranchised stepdaughters
fastidiousness lasciviousness

Step 0

Refresh the browser window  if the page has been idle for some time.

Step 1

Paste the output of your program for the long test case into the box below.

Step 2

Paste the source code for your program into the box below.

Step 3

When you are sure all the data has been entered correctly on the form press the submit button below.

You may submit multiple times. Only your most recent submission for each question will be marked.


Source: Programming Puzzles and Code Golf, contributed by user xnor.