All Submissions


Problem Statement

Before a browser renders a web-page, it must first parse the HTML code sent from the web-server to create what is known as a DOM tree. However, sometimes the HTML received is corrupt. We will be considering a simplified version of HTML here, which contains only tags and the text between tags.

Each tag consists of a sequence of alphanumeric (and no other) characters, called the name of a tag.
There are 3 types of tags: starting, ending & independent tags.
The starting tag consists of the less than symbol, the tag name and then the greater than symbol. Eg: <body>
The ending tag is like the starting tag, but with a slash before the name. Eg: </body>
The independent tag is like the starting tag, but with a slash after the name. Eg: <br/>
The text between the tags can contain only alphanumeric, space & period (.) characters.

Given that a tree needs to be constructed, valid HTML always abides by the rule: first tag on, last tag off. Given that tags can contain one another (in between the starting and ending tags), we must ensure that containment is complete, and not partial. For instance, the following is valid:

<b>Bold <i>Italic</i> Text.</b>

But this is not:

<b>Bold <i>Italic</b> Text.</i>

Because the i-tag only partially inside the b-tag. When the browser encounters this, it should close the i-tag prematurely to ensure containment and ignore the ending tag later on.

<b>Bold <i>Italic</i></b> Text.

Note that independent tags do not appear in pairs, unlike the starting & ending tags. Hence, none of the above problems are applicable to them.

Your task is to implement this mechanism. You may assume that the only problems with the input HTML are regarding containment as explained above.

Input/Output Specification.

The first line of the input will contain the number of test cases, N.
N lines will follow, each containing simplified HTML code (as specified), which may or may not be corrupt. Length of line will be less than 1000.
For each test case, print out the HTML, with corrections (as specified) made where necessary.

Sample Input


3
<b>Bold <i>Italic</b> Text.</i>
</doctype><html><head><title>BIT Mesra</title></head></html>
<a><img/>Caption


Sample Output


<b>Bold <i>Italic>/i>/b> Text.
<html><head><title>BIT Mesra</title></head></html>
<a><img/>Caption</a>


Problem Setter: Kaustubh Karkare

Languages: C,C++,C#,Java,JavaScript,Pascal,Perl,PHP,Python,Ruby

Time Limit: 1 Second(s)
Score: 100 Point(s)
Input File Limit: 50000 Bytes

Submit

Login to post clarification.

No Clarifications.

Contest

Mode Judge

Passive

Online

Overall Rankings

RankNameScore
1xyz0
2Ams0
3TIP0
4team420
5xyzz0
6asdasdasd0
7abcd0
8khankhan0
9Gabriel0
10gigel0