Meet The Plastics II


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Cady has just met Regina George, Gretchen Wieners, and Karen Smith — a clique of popular girls known as The Plastics. She loves sitting with them at lunch, but have some strict fashion rules.

Each day, Regina creates a rule that Cady must follow:

  • She either forbids Cady from wearing a list of specific colors, or
  • She requires Cady to wear a specific color.

To make things even more stressful, Cady is not allowed to wear the same color two days in a row.

Cady has a limited wardrobe. Can she plan her outfits to satisfy Regina's rules?

Input

The first line contains an integer n (1 \leq n \leq 1000) — the number of colors in Cady's wardrobe.

The next n lines each contain a color name — these are the clothes Cady owns. Each color name is a string of length 1 \leq |C| \leq 10.

The next line contains an integer n (1 \leq m \leq 1000) — the number of days Cady must follow the fashion rules.

The next m lines each describe a rule for the corresponding day. Each rule is either:

  • No k C1 C2 C3 ... Ck — Cady cannot wear any of the k forbidden colors (1 \leq k \leq 10), each color name is a string of length (1 \leq |C_i| \leq 10).

  • Yes C — Cady must wear the color C on that day.

Output

If Cady can satisfy Regina's fashion rules, output the color she should wear on each day, in order. Otherwise, output "No".

Clarifications

  • If there are multiple answers, output any of them.
  • The colors in Cady's wardrobe are unique.
  • The colors in each "No" clause are unique for that clause (e.g. No 2 Red Red is not possible).

Example

Input 1
5
Red
Blue
Green
Yellow
Pink
5
No 3 Red Green Blue
No 1 Yellow
Yes Pink
No 3 Red Green Black
Yes Yellow
Output 1
Yellow
Red
Pink
Blue
Yellow

Cady can successfully follow Regina's fashion rules.

Input 2
2
Pink
Red
3
No 3 Red Green Blue
No 3 Red Green Blue
No 3 Red Green Blue
Output 2
No

Cady can wear pink on the first day, but then she doesn't have any clothes to wear on the last two days.

Input 3
1
Red
3
No 1 Rainbow
No 1 Rainbow
No 1 Rainbow
Output 3
No

Cady doesn't have enough clothes to wear, as to not wear the same thing twice in a row.

Input 4
4
Red
Pink
Green
Blue
2
Yes Pink
Yes Pink
Output 4
No

Regina wants Cady to wear pink twice, but she can't wear the same thing twice in a row.


Comments

There are no comments at the moment.