PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000118. Tính tỉ số theo quan hệ (Evaluate Division)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tính tỉ số theo quan hệ (Evaluate Division)

Evaluate Division

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

You are given ee equations a/b=va/b=v, where aa and bb are variable names and v>0v>0. All equations are consistent and there are no division-by-zero cases. For each query x/yx/y, determine the ratio if it follows from the equations, otherwise print -1. A variable absent from all equations is undefined even for a query of the form x/xx/x.

Input

First line e,qe,q; next ee lines a,b,va,b,v, then qq lines x,yx,y. Variable names have no whitespace. This is the stdin/stdout adaptation of the LeetCode API problem.

Output

Print qq ratios, one per line, or -1 when unknown. Absolute or relative error up to 10−610^{-6} is accepted.

Subtasks

  • Subtask 1 (40 points): 1≤e≤61\le e\le 6, 1≤q≤81\le q\le 8, 0<v≤100<v\le 10. All input conditions remain in force.

  • Subtask 2 (60 points): 1≤e≤401\le e\le 40, 1≤q≤501\le q\le 50, 0<v≤1040<v\le 10^4. All input conditions remain in force.

Examples

Input

2 5
a b 2
b c 3
a c
b a
a e
a a
x x

Output

6.0000000000
0.5000000000
-1.0000000000
1.0000000000
-1.0000000000

Explanation

a/c = (a/b)*(b/c)=6; b/a=0.5; unknown variables cannot be evaluated, even in x/x.