Document Validator 

Nowadays mark-up languages like LaTeX, HTML, SGML, and XML are widely used to define, in a completely textual mode, the structure of documents. Those languages are composed by tags, or annotations, that are used to mark blocks of text (their begin and end) in order:

Tags are just words like all the others that belong to the original plain text; so, it is necessary to use some lexical convention to distinguish those special words (annotations). Also, we need some convention to identify the beginning and the end of the text block we want to annotate.

In the present context, our mark-up language follows an approach similar to the SGML based languages:

Paired tags are employed to define the document structure, while single tags are used to give meaning or formatting information. Tag names (one letter followed by zero or more letters or digits) are free, i.e. not previously defined; this means that the user of that mark-up language can choose the names of the tags he will employ to annotate his document. However, to be a valid annotation it must be in conformity with the following rules:

Given a structured document, supposed to be annotated accordingly to the mark-up language above described, write a program that validates it, that is that verifies if the tags are properly used. If the document is valid (has no errors), your program must identify all the different tag names used, separating structural and semantic ones.

Input 

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.


The input is a plain text file with tags, following the above stated conventions. Assume that lexical conventions specified for the three tag types ([opening-tag[, ]closing-tag] and {opening-closing-tag}) are always complied.

Output 

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.


The output consists of:

Sample Input 

1

[memo[
[de[ Comiss ao Cient fica do MIUP ]de]
[para[ Todos os Concorrentes ]para]
[data[{bold 2001.set.25}]data]
[mensagem[
[parag[Devem ter o m aximo cuidado na leitura dos enunciados.]parag]
[parag[Desejamos a todos {desejo Calma} e {desejo Boa Sorte}!]parag]
]mensagem]
]memo]

Sample Output 

STRUCTURAL TAGS
memo
de
para
data
mensagem
parag
SEMANTIC TAGS
bold
desejo



Pedro Henriques, MIUP'2001