#!/usr/bin/env python3

n, q = map(int, input().split())
units = []
edges = []
for _ in range(n):
    i = input().split()
    fr = i[1]
    x = float(i[3])
    to = i[4]
    if fr not in units:
        units.append(fr)
    if to not in units:
        units.append(to)
    edges.append((units.index(fr), x, units.index(to)))

for _ in range(q):
    i = input().split()
    x = float(i[0])
    fr = units.index(i[1])
    to = units.index(i[3])
    v = [0] * len(units)
    v[fr] = x
    while True:
        change = False
        for (f, y, t) in edges:
            if v[f] > 0 and v[t] == 0:
                change = True
                v[t] = v[f] * y
            if v[f] == 0 and v[t] > 0:
                change = True
                v[f] = v[t] / y
        if not change or v[to] > 0:
            break
    if v[to] > 0:
        print(v[to])
    else:
        print("impossible")
