#C9765. Interstellar Programming Contest

    ID: 53894 Type: Default 1000ms 256MiB

Interstellar Programming Contest

Interstellar Programming Contest

The Galaxy Federation is holding an interstellar programming contest. In this contest, each team is assigned a spaceship and must complete a series of missions during a long space journey. Each mission outcome affects the team's energy points:

  • S: Successful mission, awarding \(+3\) energy points.
  • E: Encounter with space pirates, costing \(-1\) energy point.
  • N: Neutral outcome, no change in energy points.

After all missions are completed, teams are ranked based on the following criteria:

  1. Higher total energy points.
  2. If tied, the team with more successful missions (i.e. more S outcomes) is ranked higher.
  3. If still tied, the team with fewer encounters with space pirates (i.e. fewer E outcomes) wins.
  4. If all criteria are the same for the top teams, the result is a tie.

Your task is to identify the overall winner for each test case. In the case of a tie, output 'Tie'. Teams are numbered starting from 1.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
M
team1
team2
... 
teamM
... (repeated for T test cases)

Where:

  • T is the number of test cases.
  • For each test case, M is the number of teams.
  • Each team is described by a string of characters, where each character is one of S (successful mission), E (encounter with space pirates), or N (neutral outcome). Only S and E affect the energy points.

outputFormat

For each test case, output the winning team number on a new line. If there is a tie, output Tie. The output should be written to standard output (stdout).

## sample
2
3
SSNN
SSEW
SENNN
2
SESENS
ENS
1

1

</p>