Polygraph (Small)

No attempts yetTime limit5sMemory limit512 MB

Problem

The distant island of Googlia has two cities. Everyone from Truthtown always tells the truth, and everyone from Liarville always lies. While exploring Googlia you meet NN inhabitants, and you want to work out which city each one comes from.

You first number these people from 1 to NN. You then question them one by one and record their MM statements in the shorthand below.

ShorthandMeaning
i T jPerson ii says, "Person jj is from Truthtown."
i L jPerson ii says, "Person jj is from Liarville."
i S j kPerson ii says, "Persons jj and kk are from the same city."
i D j kPerson ii says, "Persons jj and kk are from different cities."

Deduce which city each person comes from. At least one assignment consistent with all the statements is guaranteed to exist.

For example, suppose the statements are 1 D 2 3, 1 D 2 4, 1 D 3 4 and 2 L 1. Then you can reason as follows.

  • There are only two cities, so persons 2, 3 and 4 cannot all come from different cities.
  • So at least one of person 1's claims is a lie.
  • So person 1 is from Liarville, and every claim of person 1 is a lie.
  • So persons 2, 3 and 4 all come from the same city.
  • Person 2's claim is true, so person 2 is from Truthtown.
  • So persons 3 and 4 are from Truthtown as well.

Input

The first line contains the number of test cases TT. TT test cases follow. The first line of each test case contains the integers NN and MM, separated by a space. The next MM lines each contain one statement from one inhabitant, written in the shorthand above.

Limits

  • 1T1001 \le T \le 100
  • 1N101 \le N \le 10
  • 1M5001 \le M \le 500
  • 1i,j,kN1 \le i, j, k \le N
  • Within one statement, jj and kk are different.

Output

For each test case, print one line in the form Case #x: y1 y2 ... yN, where xx is the test case number starting from 1 and yiy_i is a single character telling which city person ii comes from. Separate the NN characters with one space.

  • If the statements imply that person ii must be from Truthtown, then yiy_i is T.
  • If they imply that person ii must be from Liarville, then yiy_i is L.
  • If the statements are not enough to decide, then yiy_i is -.