You've successfully subscribed to The Poor Coder | Hackerrank Solutions
Great! Next, complete checkout for full access to The Poor Coder | Hackerrank Solutions
Welcome back! You've successfully signed in.

## HackerEarth - Molly And Flame Solution

Beeze Aal

Molly is in love with Sherlock. She wants to decide the nature of the relationship between her and Sherlock using the game of FLAME.

FLAME stands for:
{āFriendshipā,āLoveā,āAffectionā,āMarriageā,āEnemiesā}

The rules of FLAME are:

1) The names of the two people are taken.

2) Then the common letters are deleted from both the names.

3) Then x_rem is calculated which is the number of leftover letters in both the names.

4) Count through the letters of āFLAMEā x_rem times. After you have counted the 5 letters of āFLAME,ā you can continue counting from 6 to 10 starting again at āFā and ending at āE,ā if needed. If you have more than 10 leftover letters, repeat the process a third time, starting with āF.ā

5) The letter at which you stop decides the nature of the relationship.

Example:

1)consider the strings sherlock and molly.

2)After striking off the common letters: sherck my

3) x_rem = len(sherck) + len(my) = 8

4) counting through the letters of FLAME.

FLAME
12345
678

5) The count stops at A. Hence the result is Affection.

However, Molly is not happy with the result of the game(Affection) and she manipulates the string FLAME TO FALME to change the result of the game(Love).

Given two names perform a minimum number of swaps on the string āFLAMEā and print the new string so that the nature of the relationship is always Love.

Input Format:
First-line containing a number of test cases t. Next t lines contain two space-separated names in lowercase.
Output Format:
Print the new string in a new line for each test case.

Constraints:

• 1ā¤Tā¤100
• 1ā¤lengthofnameā¤100000

SAMPLE INPUT

2
sherlock molly
watson mary

SAMPLE OUTPUT

FALME
FALME

### Solution in Python

t = int(input())
for _ in range(t):
a,b = input().strip().split()
c = set(a) & set(b)
l = (sum(1 for i in a+b if i not in c)%5 or 5)-1
s = list("FLAME")
s[l],s[1] = s[1],s[l]
print(*s,sep="")