#C12820. Remove Duplicate Words in Phrases

    ID: 42290 Type: Default 1000ms 256MiB

Remove Duplicate Words in Phrases

Remove Duplicate Words in Phrases

Given a list of phrases, each phrase consisting of words separated by spaces, your task is to remove all duplicated words from each phrase while preserving the original order of their first occurrences. Formally, for a phrase \(P = w_1 w_2 \ldots w_n\), generate a new phrase \(P'\) such that if a word \(w_i\) appears more than once, only its first occurrence is kept.

For example, if the input phrase is "cake and and pie are are delicious", the output should be "cake and pie are delicious".

Please note that the input is provided via standard input (stdin) and the output must be printed to standard output (stdout). Each test case begins with an integer representing the number of phrases followed by that many lines, each containing one phrase.

inputFormat

The input begins with a single integer \(N\) denoting the number of phrases. Each of the next \(N\) lines contains a phrase, which is a sequence of words separated by spaces.

Input Format:

N
phrase1
phrase2
... 
phraseN

outputFormat

Output \(N\) lines where each line is the processed phrase with duplicate words removed, while retaining the words in their original order.

Output Format:

processed_phrase1
processed_phrase2
... 
processed_phraseN
## sample
3
cake and and pie are are delicious
the the quick fox fox jumps
happy days days are are here
cake and pie are delicious

the quick fox jumps happy days are here

</p>