This page is still under construction.

Parts of this page are still being built. What you see may change.

Word Swap

Time limit1sMemory limit256 MB

Summary
Sum the per-position letter differences between each pair of equal-length words and report the coins earned, paid, or free.
Level

Easy2 of 10

Topics
Implementation, String
Solved
No attempts yet

Problem

The carnival is running a new game next year. The carnival worker picks a word, writes it on a piece of paper, and tells you only its length. Call the written word Word 1, and call the word of the same length that you guess Word 2. You earn or pay coins according to how different the two words are, that is, how much work it takes to swap the letters of Word 1 into the letters of Word 2. Agnes just turned 6, has barely started reading, and cannot do arithmetic yet, so she wants help playing this game.

The carnival set these coin rules.

  • The game uses only the letters a to z.
  • The difference between the words is decided position by position.
  • At each position: (1) if the two letters are the same, no coin is paid or earned. (2) if the letter of Word 1 comes before the letter of Word 2 in the alphabet, you pay 1 coin for every letter that sits between the two letters, plus 1 more coin. (3) if the letter of Word 1 comes after the letter of Word 2, you earn that same amount.

For example, if the carnival worker writes agnes and you guess heard, the calculation is the table below.

Position 1Position 2Position 3Position 4Position 5Total
Carnival wordagnes
Your wordheard
Coinspaid 7earned 2earned 13paid 13earned 15earned 10

Add the coins earned at each position and subtract the coins paid to get the total for the pair. A positive total is what you earn, a negative total is what you pay, and a total of 0 moves no coins.

You might call this a dull game, since guessing a word like aal or abut of the right length always earns coins. The real carnival game adds a twist: earn too much and you get nothing. This problem ignores that twist.

Write a program that reads several pairs of words and reports the coins earned or paid for each pair.

Input

The first line contains the number of test cases TT. (1≤T≤10001 \le T \le 1000)

Each of the next TT lines contains two words separated by one space. The first word is Word 1 and the second word is Word 2. The two words have the same length, consist of lowercase letters only, and have length between 1 and 100.

Output

Print one line per test case. Let A be Word 1, B be Word 2, and SS be the total.

  • If S>0S > 0, print Swapping letters to make A look like B earned S coins.
  • If S<0S < 0, print Swapping letters to make A look like B cost S coins., where S is replaced by the absolute value of the total.
  • If S=0S = 0, print Swapping letters to make A look like B was FREE.

Write coins even when the amount is 1.

Examples2

  1. Example 1

    Input
    4
    agnes heard
    unicorn minions
    victor vector
    sweat waste
    
    Expected output
    Swapping letters to make agnes look like heard earned 10 coins.
    Swapping letters to make unicorn look like minions earned 1 coins.
    Swapping letters to make victor look like vector earned 4 coins.
    Swapping letters to make sweat look like waste was FREE.
    
  2. Example 2

    Input
    3
    a z
    z a
    m m
    
    Expected output
    Swapping letters to make a look like z cost 25 coins.
    Swapping letters to make z look like a earned 25 coins.
    Swapping letters to make m look like m was FREE.