#K92827. Clean the Playlist

    ID: 38284 Type: Default 1000ms 256MiB

Clean the Playlist

Clean the Playlist

You are given one or more playlists, where each playlist is represented by a comma‐separated string of song names. Some songs may appear multiple times in a playlist.

Your task is to remove duplicate occurrences of songs while preserving the original order in which they appear.

For example, given the playlist:

songA,songB,songA,songC,songB

the cleaned playlist should be:

songA,songB,songC

In mathematical terms, if the input list is \(a_1,a_2,\dots,a_n\), you should output a list \(b_1,b_2,\dots,b_m\) where \(\{b_j\}\) is the sequence of distinct elements in the order of their first appearance.

inputFormat

The input begins with a single integer \(T\) on the first line, representing the number of test cases. Each of the following \(T\) lines contains a non-empty string representing a playlist. The songs in a playlist are separated by commas ",".

Example:

2
songA,songB,songA,songC,songB
hit1,hit2,hit2,hit1,hit3,hit3

outputFormat

For each test case, output a single line containing the cleaned playlist with duplicates removed (preserving the order of first occurrence) and songs separated by commas.

Example:

songA,songB,songC
hit1,hit2,hit3
## sample
2
songA,songB,songA,songC,songB
hit1,hit2,hit2,hit1,hit3,hit3
songA,songB,songC

hit1,hit2,hit3

</p>