RAFANOLE - Nadal vs Djokovic

Rafael Nadal vs Novak Djokovic is probably the fiercest rivalry in tennis right now. Now your task is very simple. You are given a string containing the scores of a single set (a set consists of many games) between these two stalwarts. N denotes Nadal and D denoted Djokovic. For those who are new to tennis, have a look of the rules online. Anyway small description about the rules:

Now how a player wins a single game?

In a game scores are incremented as follows: 15, 30, 40. A player wins if scores are like 40-0, 40-15, 40-30. If tied at 40-40, it is called deuce. If N wins next he has an advantage and if he loses the next volley he comes back to deuce. After advantage if the player wins the next volley he wins that game.

Simply put the player who wins 6 games first (provided he has won two games more than his opponent) wins the set. For example, 6-1, 6-2, 6-3, 6-4 are all valid.

If 1 player has won 6 games and the other has won 5 games the match continues. (7-5 is also a valid scoreline.)

If both the players are deadlocked at 6-6, then we have a tiebreaker. In the tiebreaker the scores are counted normally (1, 2, 3...) The person who reaches 7 points first and is at least 2 more than his opponent wins the set. Example: 7-0, 7-1, 7-2 ... 7-5 are valid. If the score is 7-6 the match proceeds until one of the players scores two points more than the other, for example: even 10-8 is valid.

Input

1st line - number of test cases

Next T lines consist of strings denoting who won a volley.

Output

Output the winner, their score, and the tie breaker score if any in the first line.

Output the loser and their score on the second line.

See the sample out for the required formatting.

Example

Input:
2
N N N N N N N N N N N N N N N N N N N N D D D D D D D D N N N N
D D D D N N N N D D D D N N N N D D D D N N N N D D D D N N N N D D D D N N N N D D D D N N N N D D D D D D N N N N N D

Output:
N 6
D 2
D 7 (7-5)
N 6

Added by:n.7n
Date:2013-10-21
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own

hide comments
2013-11-16 20:29:18 Saimadhav Heblikar
heads up,the there is no \n after each test case(as shown in the sample).cost me 4 nzec
2013-11-16 20:29:18 Mahesh Mishra
My 200th :)

Last edit: 2013-11-04 13:55:14
2013-11-16 20:29:18 Praveen Selvaraj
For each test case I gave read input till '\n' and it was TLE, changed it to EOF and its giving WA!
Checked output for all possible test cases!!
GOT AC!! For those who are having trouble accept each case as a string using getline and then process.

Last edit: 2013-11-04 17:14:54
2013-11-16 20:29:18 /* EDWARD KENWAY */
@Bolt please check my code,my submission ID 10404517.. getting WA even when it gives correct output for all test cases
2013-11-16 20:29:18 Arpit Uppal
@N.7N check my submission ID 10388250.. getting WA even when it runs fine for all test cases

Last edit: 2013-11-13 15:30:08
2013-11-16 20:29:18 Arpit Uppal
Getting WA even when it gives correct output on ideone for all possible cases :(
2013-11-16 20:29:18 n.7n
@Abhishek Yadav : Input length is not specified in the problem. So u shall proceed accordingly :)
2013-11-16 20:29:18 Abhishek Yadav
we have to read input till what??
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.