A consulting firm keeps its staff in an organization tree. One employee is one node, the head of the firm is the root, and every node carries a job title as its label.
A management journal printed a list of patterns that a study calls dangerous. One example is an engineer with an economist somewhere above him. A pattern is itself a rooted tree whose labels are job titles.
A pattern P occurs in an organization tree T when some map f from the nodes of P to the nodes of T satisfies all of the following.
One edge of the pattern may stretch into a long path of the organization tree. Two pattern nodes with no ancestor relation between them must map to two nodes where neither is an ancestor of the other.
You are given the organization tree and a list of patterns. Decide for each pattern whether it occurs in the organization tree.
The first line holds the organization tree T as one string with no spaces. The number of nodes n satisfies 1≤n≤10000. A node is written as its label, followed, when it has children, by its child list in parentheses with the children separated by commas. A label is a string of 1 to 10 lowercase letters.
The second line holds the number of patterns q, with 1≤q≤100.
Each of the next q lines holds one pattern tree in the same format. The number of nodes m of a pattern satisfies 1≤m≤16.
Print one line per pattern. Print disaster if the pattern occurs in the organization tree, and great success otherwise.