1025 - Following Orders

通过次数

0

提交次数

0

Time Limit : 1 秒
Memory Limit : 128 MB

Order is an important concept in mathematics and in computer science. For example, Zorn's Lemma states: ``a partially ordered set in which every chain has an upper bound contains a maximal element.'' Order is also important in reasoning about the fix-point semantics of programs. This problem involves neither Zorn's Lemma nor fix-point semantics, but does involve order. 
Given a list of variable constraints of the form x < y, you are to write a program that prints all orderings of the variables that are consistent with the constraints.
For example, given the constraints x < y and x < z there are two orderings of the variables x, y, and z that are consistent with these constraints: x y z and x z y.  


根据给出的多个约束条件,编写一个程序来列出所有符合这些约束条件的排列。
例 :
根据x<y,x<z可得出x,y,z共有2个排列的序列:
x y z
x z y

Input

The input consists of a sequence of constraint specifications. A specification consists of two lines: a list of variables on one line followed by a list of contraints on the next line. A constraint is given by a pair of variables, where x y indicates that x < y.

All variables are single character, lower-case letters. There will be at least two variables, and no more than 20 variables in a specification. There will be at least one constraint, and no more than 50 constraints in a specification. There will be at least one, and no more than 300 orderings consistent with the contraints in a specification.

Input is terminated by end-of-file. 
一组输入包含两行
第一行是这个序列中的所有元素,所有的变量元素为单个小写字母,个数大于等于2且不超过20.
第二行 两个两个一组,(x y) 表示(x<y).至少一组条件且不起过300组条件。

Output

For each constraint specification, all orderings consistent with the constraints should be printed. Orderings are printed in lexicographical (alphabetical) order, one per line.

Output for different constraint specifications is separated by a blank line.  


【输出每一组可能的排序,不同组之间的输出有一行空格】

Examples

Input

a b f g
a b b f
v w x y z
v y x v z v w v

Output

abfg
abgf
agbf
gabf

wxzvy
wzxvy
xwzvy
xzwvy
zwxvy
zxwvy