The Revenge of Jalebi Bai

All submissions for this problem are available.
Jalebi Bai recently met her long time friend Barfi Tai. Instead of entertaining her guest, Barfi Tai kept boasting about her K marvelous necklaces made of black and golden beads. Jalebi Bai felt really jealous of it and decided to exact revenge.
She has invited Barfi to visit her home next week. Meanwhile, she is planning to buy a truly beautiful necklace to make Barfi jealous. According to her, a truly beautiful necklace should contain each of Barfi’s necklaces as a subsequence of it. Though still trying to show off, Jalebi Bai is smart and does not want to put a lot of money in it. So she wants to buy a truly beautiful necklace containing the minimum number of beads.
She goes to Devu Sunar and asks him to provide her such a necklace. Devu Sunar is busy this week and has asked you to help him in building the necklace. Please help him!
Note
 A subsequence is a sequence that can be derived from another sequence by deleting some elements but without changing the order of the remaining elements. For example, the sequence [A,B,D] is a subsequence of [A,B,C,D,E,F].
 The bead patterns on the necklaces are not considered circular.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases is as follows.
The first line of each test case contains an integer K denoting the number of necklaces of Barfi.
K lines follow. Each of them contains a string made from the characters ‘B’ (representing black bead) and ‘G’ (representing golden bead), with the i^{th} line denoting Barfi Tai's ith necklace.
Output
For each test case, output a truly beautiful necklace with the minimum number of beads. If there are more than one such necklace, you are allowed to print any of them.
Constraints
 1 ≤ T ≤ 30
 1 ≤ K ≤ 16
 1 ≤ length of each necklace of Barfi ≤ 8
Example
Input: 3 2 BG GB 2 BGB GG 3 BG GBB BGB Output: BGB BGGB BGBB
Explanation
In the first example,
Devu can give necklace the BGB to Jalebi Bai, as it contains both the Barfi's necklace BG and GB as subsequence.
Note that Devu can also give GBG to Jalebi Bai.
In the second example,
Devu can give the necklace BGGB, as it contains both the Barfi's necklace BGB and GG as subsequence.
Note that there are many other possible truly beautiful necklaces of length 4, that Devu can give, e.g. BGBG or GBGB.
You are allowed to print any of them.
In the third example,
Devu can give the necklace BGBB or GBGB. You are print any of them as your answer.
Author:  admin2 
Editorial  http://discuss.codechef.com/problems/KOL1510 
Tags  acm15kol, admin2, backtracking, shortest, supersequence 
Date Added:  12122015 
Time Limit:  3 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYP3 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 