Shortest Accepted Word

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

In this problem, we consider strings consisting of lowercase Latin letters "a", "b" and "c".

For this problem, let us define a regular expression recursively as follows:

  1. A single character "$" is a regular expression accepting the empty string.
  2. Single characters "a", "b" and "c" are regular expressions accepting strings "a", "b" and "c", respectively.
  3. If PP is a regular expression, "(PP)" is also a regular expression accepting  all strings accepted by PP.
  4. If PP is a regular expression which is a direct result of applying any of the rules 1--4, its iteration, denoted as "PP*", is also a regular expression accepting strings of the form s=u_1u_2u_ks = u\_1 u\_2 \ldots u\_k (a concatenation of zero or more strings) where kk is any non-negative integer and each string u_iu\_i is accepted by PP.
  5. If PP and QQ are regular expressions which are direct results of applying any of the rules 1--5, their concatenation, denoted simply as "PP{}QQ", is also a regular expression accepting strings of the form s=uvs = u v (a concatenation of uu and vv, each of which may be empty) where the prefix uu is accepted by PP and the suffix vv is accepted by QQ.
  6. If PP and QQ are regular expressions which are direct results of applying any of the rules 1--6, their union, denoted as "PP|QQ", is also a regular expression accepting both strings accepted by PP and strings accepted by QQ.

The restrictions in rules 4--6 are imposed to prevent ambiguities and prioritize operations: when reading a regular expression, evaluate iteration, then concatenation, then union. Parentheses play the usual role of prioritizing operations enclosed in them. For example, the regular expression "a(bac|ac*)" is read as "accept a followed by either (b followed by a followed by c) or (a followed by zero or more copies of c)".

Given a regular expression rr, find the shortest string ss which is accepted by this regular expression rr. If there are several such strings, find the lexicographicaly smallest one.

입력

The first line of input contains one integer TT, the number of test cases (1T3001 \le T \le 300).

Each of the next TT lines describes a single test case. Each test case description consists of a regular expression rr which is a string constructed by the above rules. Its length is from 11 to 300300 characters.

The sum of all lengths of regular expressions is not greater than 300300.

출력

For each test case print a single line containing the shortest string accepted by the given regular expression rr. If there is more than one such string, print the lexicographically smallest one.

If the answer is an empty string, print a single character "$" instead.