import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Tagless
* In a tag-based language like XML or HTML, contents are enclosed between a
* start tag and an end tag like contents. Note that the
* corresponding end tag starts with a /.
*
* Given a string of text in a tag-based language, parse this text and retrieve
* the contents enclosed within sequences of well-organized tags meeting the
* following criterion:
*
* The name of the start and end tags must be same. The HTML code
*
Hello World is not valid, because the text starts with an h1 tag and
* ends with a non-matching h2 tag.
*
* Tags can be nested, but content between nested tags is considered not valid.
* For example, in
* , contents is valid but invalid is not valid.
*
* Tags can consist of any printable characters.
*
* Input Format
*
* The first line of input contains a single integer,
* (the number of lines).
* The
*
* subsequent lines each contain a line of text.
*
* Constraints
*
* Each line contains a maximum of
* printable characters.
* The total number of characters in all test cases will not exceed
*
* .
*
* Output Format
*
* For each line, print the content enclosed within valid tags.
* If a line contains multiple instances of valid content, print out each
* instance of valid content on a new line; if no valid content is found, print
* None.
*
* Sample Input
*
* 4
* Nayeem loves counseling
*
* Sanjay has no watch
So wait for a while
* safat codes like a ninja
* Imtiaz has a secret crush
*
* Sample Output
*
* Nayeem loves counseling
* Sanjay has no watch
* So wait for a while
* None
* Imtiaz has a secret crush
*
*/
public class Tagless {
public static String tags;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < n; i++) {
String line = scanner.nextLine();
Taglesstags(line);
}
scanner.close();
}
private static void Taglesstags(String line) {
String tagPattern = "<([^>]+)>([^<>]+)\\1>";
Pattern pattern = Pattern.compile(tagPattern);
Matcher matcher = pattern.matcher(line);
boolean found = false;
// let's loop through all the lines
while (matcher.find()) {
System.out.println(matcher.group(2));
found = true;
}
if (!found) {
System.out.println("None");
}
}
}