Meet The Plastics I


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.

Luckily, Cady is allowed to wear the same color any number of times.

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 C — these are the colours of clothes Cady owns. Each color name is a string of length 1 \leq |C| \leq 10.

The next line contains an integer m (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
Pink
Pink
Pink

Cady can successfully follow Regina's fashion rules.

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

Cady can't avoid wearing rainbow.

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

Cady can't wear pink when Regina wants her to.


Comments

There are no comments at the moment.