Time Limit:3000ms Memory Limit:65536KB

## Description

Cauchy never remembered his course schedule completely , he only knows the time of M courses excatly and the gap between N pairs of courses . If one day Cauchy attended course A and g days later , he attended course B , we say g is a gap between courses A and B . Notice that the gap between courses A and B is not only one , because any course on cauchy's course schedule occurs only once in one week (it's impossible in real world) , and the course schedule is the same every week . So if g is a gap between course A and B , 7 + g is also a valid gap . And the gap between course A and B is not the same as the gap between course B and A . cauchy wants to know when to attend a course , but he is very busy . So he teld you what he rememberd and wanted you to tell him the time to attend a course . Each course is represented by a space-free string with length less than 200 .

## Input

The input consists of multiple test cases . The first line of each test contains two integers M (1<=m<=16) , n (1<=N<=16) as descripted , then followed M lines , each line conatins a string A and an integer d (1<=d<=7) , d = 1 , 2 , ... , 7 means the course A is on Monday , Tuesday , ... , Sunday . then followed N lines , each line contains two strings A and B , and a non-negative integer g , stands for the gap between course A and B is g . then a single line contains an integer Q (1<=Q<=20) , stands for Cauchy wants to know the time of Q courses . then Q lines followed , each line contains only one string A . The total course names occured in the input will not exceed 50 . And Cauchy never remember wrong things . There is a blank line after each test case .

## Output

Output Q lines each contains a single integer d (1<=d<=7) , tells Cauchy the time of each course he wants to know . If the the time can not be decided , just output "Not Sure" . Output a blank line after each test case .

## Sample Input

```1 1
Algebra 2
Algebra NumberTheory 6
2
Algebra
NumberTheory

3 3
TheCPlusPlus 4
PE 1
English TheCPlusPlus 2
Physics Cisco 1
7
English
PE
TheCPlusPlus
Physics
Cisco
Analysis
```

```2
1

1
2
1
4
Not Sure
Not Sure
Not Sure

```

cauchy