import java.util.*; import java.io.*; import java.text.*; public class NickyEnMark{ public static void main(String[] args) throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { String[] line = reader.readLine().split(" "); int n = Integer.parseInt(line[0]); int q = Integer.parseInt(line[1]); HashMap> graph = new HashMap<>(); for (int i = 0; i < n; i++) { line = reader.readLine().split(" "); String source = line[1]; String target = line[4]; double conversion = Double.parseDouble(line[3]); double conversionInverse = 1 / conversion; addEdge(graph, source, target, conversion); addEdge(graph, target, source, conversionInverse); } for (int i = 0; i < q; i++) { line = reader.readLine().split(" "); double multiplier = Double.parseDouble(line[0]); String source = line[1]; String target = line[3]; double conversion = bfs(graph, source, target, multiplier); if (conversion == -1) { System.out.println("Impossible"); } else { System.out.println(conversion); } } } } static void addEdge(HashMap> graph, String source, String target, double conversion) { if (!graph.containsKey(source)) { graph.put(source, new HashMap()); } graph.get(source).put(target, conversion); } static double bfs(HashMap> graph, String source, String target, double multiplier) { HashMap visited = new HashMap<>(); visited.put(source, multiplier); Queue q = new LinkedList<>(); q.add(source); while (!q.isEmpty()) { String node = q.remove(); if (target.equals(node)) { return visited.get(target); } for (String node2 : graph.get(node).keySet()) { if (visited.containsKey(node2)) { continue; } visited.put(node2, visited.get(node) * graph.get(node).get(node2)); q.add(node2); } } return -1; } }