#include <cstdio>#include <cstring>#include <string>#include <set>#include <iostream>using namespace std;char stk[1000][280];char hd[280], var[280], s[280];set<string> ST;int main(void){ int T, i, j, pre, L, R; scanf("%d", &T); getchar(); while(T--) { ST.clear(); getchar(); gets(s); int ansCnt = 0; int top = 0; strcpy(stk[top++], s); while(top) { -- top; strcpy(hd, stk[top]); if(strchr(hd, '[') == NULL) { ST.insert(string(hd)); continue; } int len = strlen(hd); L = strchr(hd, '[') - hd; int cnt = 0; for(i = L+1; i < len; ++i) { if(cnt == 0 && hd[i] == ']') break; if(hd[i] == '[') ++cnt; if(hd[i] == ']') --cnt; } R = i; strncpy(s, hd, L); strncpy(var, hd+L+1, R-L-1); j = R-L-1; pre = cnt = 0; for(i = 0; i < j; ++i) { if(var[i] == '[') ++cnt; if(var[i] == ']') --cnt; if(cnt == 0 && var[i] == '|') { strncpy(s+L, var+pre, i-pre); strncpy(s+L+i-pre, hd+R+1, len-R); strcpy(stk[top++], s); pre = i+1; } } strncpy(s+L, var+pre, j-pre); strncpy(s+L+j-pre, hd+R+1, len-R); strcpy(stk[top++], s); } for(set<string>::iterator it = ST.begin(); it != ST.end(); ++it) cout << *it << endl; if(T) putchar('n'); } return 0;}