chimie

The apprentice wizard has taken the magic vial and is pouring in it doses from the master's 32 magical potions. The potions are placed in consecutive layers and sometimes the poured dose reacts with potions already in the vial, so after a number of operations the apprentice is wondering what potions are still in the vial.
 The following is known:
- there are m combinations of potions which if found in successive layers (without any other substances between them) create a different potion
- the order in which reacting potions are placed is irrelevant; their quantity matters though, more specifically the reaction only takes place if there is a single dose of the potion, and the result is also a single dose of the new potion
- two consecutive doses of the same potion react, resulting in one dose of the same potion.
- if more than one reaction is possible the one involving the least number of potions takes place.
A potion is identified by one of the 26 capital letters of the English alphabet or one of digits 1, 2, 3, 4, 5, 6.
A reaction is specified as s1s2...sk=s, where s1, s2, ..., sk are potions that combine and s is the potion that results from the reaction.

Task

Establish what potions can be found in the vial after n operations.

Input Data

The first line of input file chimie.in contains positive integers m and n: the number of possible chemical reactions and the number of doses poured in the vial. The next m lines contain chemical reactions, one reaction per line. The next n lines contain the potions in the order in which they are poured in the vial, one potion per line.

Output Data

Line one of file chimie.out will contain  the number of potions existing in the vial at the end. The next lines contain the potions, one per line, in layered order, starting with the bottom-most layer.

Constraints

Example

chimie.in

chimie.out

Explanation

4 8
ABC=D
BD=C
CDA=B
AD=C
E
A
B
A
D
C
B
D

3
E
D
C

1. E
2. EA
3. EAB
4. EABA
5. EABAD=>EABC=>ED
6. EDC
7. EDCB
8. EDCBD=>EDCC=>EDC

Time limit: 0.3 seconds/test

prof. Nistor Mot
Braila "N.Balcescu" National High School
Contact:emotz_ro@yahoo.co.uk