Leila is a Bioinformatician, interested in studying Bacterial evolution. In one experiment on a special type of bacteria, she started from a single bacterium, put it on a plate, and monitored the bacterial division, until she obtained a population of
k
k bacteria. During the process, she carefully reported the evolutionary relationships between bacteria. Precisely, for each bacterium, she reported its parent bacterium.

In the next step, she extracted DNA sequences of
k
k bacteria in the final population, by NGS technology. Each DNA sequence is represented as a string of length
m
m from the alphabet set
A
,
T
,
c
,
G
A, T, C, G.

The NGS technology has a drawback: it produces a lot of missing values. So, there are a lot of unknown characters indicated by ? in the extracted sequences. Considering the evolutionary relationship between bacteria, Leila wants to impute the missing values. Among all possible imputations, she wants to find the minimum cost imputation from an evolutionary perspective.

The problem is defined as follows. A rooted tree
T
T is given, and for each leaf
v
v of
T
T, a string
b
v
b
v
​
 of length
m
m from the character set
A
,
T
,
c
,
G
,
?
A, T, C, G,? is given. A transition cost matrix
Δ
Δ is also given, where
Δ
(
x
,
y
)
(
x
,
y
∈
A
,
T
,
c
,
G
)
Δ(x,y)(x,y∈A,T,C,G) represents the cost of a transition from an
x
x character to a
y
y character, from a parent to his child.

A feasible imputation, assigns a string su of length
m
m from the character set
A
,
T
,
c
,
G
A, T, C, G to each vertex
u
u, where for each leaf
v
v of
T
T
s
v
s
v
​
 is equal to
b
v
b
v
​
 except for? characters in
b
v
b
v
​
 . The evolutionary cost of an imputation is defined as the sum of evolutionary costs of all edges. The evolutionary cost of an edge between parents
u
u and child
w
w, is defined as
∑
i
=
1
m
Δ
(
s
u
[
i
]
,
s
w
[
i
]
)
∑
i=1
m
​
 Δ(s
u
​
 [i], s
w
​
 [i]), where
s
u
[
i
]
s
u
​
 [i] is the
i
i-th character of
s
u
s
u
​
 .

Leila wants to find a feasible imputation for
T
T, which has the minimum evolutionary cost among all feasible imputations. The tree
T
T, transition cost matrix
Δ
Δ, and a string
b
v
b
v
​
 for each leaf
v
v are given. You should write a program to calculate the minimum evolutionary cost of feasible imputations.

input
The first line of the input contains an integer
n
n (
2
≤
n
≤
10
,
000
2≤n≤10,000) denoting the number of vertices of
T
T. The vertices of
T
T are numbered from
1
1 to
n
n. The root of the tree is numbered
1
1. The root is never considered as a leaf, even if it has only one child. The next
n
-
1
n−1 lines describe the edges of
T
T; each line contains two endpoints of an edge separated by spaces. In the next four lines, the evolutionary cost matrix
Δ
Δ is given; each line is for one row of
Δ
Δ. Rows (corresponding to a parent) and columns (corresponding to a child) of
Δ
Δ are ordered to respectively represent characters
A
,
T
,
c
A, T, C and
G
G. All entries of
Δ
Δ are non-negative integers not more than
1
0
6
10
6
 . The next line just contains
k
k, the number of leaves. Finally, each leaf
v
v (its number) and its
b
v
b
v
​
 which is a string of size
m
m (
1
≤
m
≤
200
1≤m≤200) appear in one line.

output
In one line, print the minimum evolutionary cost of feasible imputations.

Example
Sample entry 1
3
1 2
1 3
0 3 4 4
4 0 4 4
4 4 2 4
1 1 1 0
2
2 AAC
3 T?C
Plain text
Sample output 1
4     write in c++