import java.io.*; import java.util.*; public class Maarten { public static void main(String[] args) throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { new Maarten().run(reader); } } public void run(BufferedReader reader) throws IOException { String[] firstLine = reader.readLine().split(" "); int n = Integer.parseInt(firstLine[0]); int q = Integer.parseInt(firstLine[1]); Map> units = new HashMap<>(); for (int i = 0; i < n; i++) { String[] line = reader.readLine().split(" = "); String a = line[0].substring(2); String[] split = line[1].split(" "); double x = Double.parseDouble(split[0]); String b = split[1]; if (!units.containsKey(a)) units.put(a, new HashMap<>()); if (!units.containsKey(b)) units.put(b, new HashMap<>()); units.get(a).put(b, x); units.get(b).put(a, 1 / x); } for (int i = 0; i < q; i++) { String[] line = reader.readLine().split(" to "); String[] split = line[0].split(" "); double x = Double.parseDouble(split[0]); String a = split[1]; String b = line[1]; HashMap seen = new HashMap<>(); seen.put(a, x); Queue todo = new LinkedList<>(); todo.add(a); while (!todo.isEmpty()) { String curr = todo.peek(); if (curr.equals(b)) { System.out.println(seen.get(b)); break; } todo.remove(); units.get(curr).forEach((k, v) -> { if (!seen.containsKey(k)) { seen.put(k, seen.get(curr) * v); todo.add(k); } }); } if (todo.isEmpty()) System.out.println("impossible"); } } }