eolymp
bolt
Try our new interface for solving problems
Məsələlər

Fiber Network

Fiber Network

Several startup companies have decided to build a better Internet, called the "FiberNet". They have already installed many nodes that act as routers all around the world. Unfortunately, they started to quarrel about the connecting lines, and ended up with every company laying its own set of cables between some of the nodes. Now, service providers, who want to send data from node \textbf{A} to node \textbf{B} are curious, which company is able to provide the necessary connections. Help the providers by answering their queries. \InputFile The input contains several test cases. Each test case starts with the number of nodes of the network \textbf{n}. Input is terminated by \textbf{n=0}. Otherwise, \textbf{1} ≤ \textbf{n} ≤ \textbf{200}. Nodes have the numbers \textbf{1}, ..., \textbf{n}. Then follows a list of connections. Every connection starts with two numbers \textbf{A}, \textbf{B}. The list of connections is terminated by \textbf{A=B=0}. Otherwise, \textbf{1} ≤ \textbf{A}, \textbf{B} ≤ \textbf{n}, and they denote the start and the endpoint of the unidirectional connection, respectively. For every connection, the two nodes are followed by the companies that have a connection from node \textbf{A} to node \textbf{B}. A company is identified by a lower-case letter. The set of companies having a connection is just a word composed of lower-case letters. After the list of connections, each test case is completed by a list of queries. Each query consists of two numbers \textbf{A}, \textbf{B}. The list (and with it the test case) is terminated by \textbf{A=B=0}. Otherwise, \textbf{1} ≤ \textbf{A}, \textbf{B} ≤ \textbf{n}, and they denote the start and the endpoint of the query. You may assume that no connection and no query contains identical start and end nodes. \OutputFile For each query in every test case generate a line containing the identifiers of all the companies, that can route data packages on their own connections from the start node to the end node of the query. If there are no companies, output "\textbf{-}" instead. Output a blank line after each test case. \includegraphics{https://static.e-olymp.com/content/e5/e5d58983bdf0b184426776fb8468b1135abe63d4.jpg}
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3
1 2 abc
2 3 ad
1 3 b
3 1 de
0 0
1 3
2 1
3 2
0 0
2
1 2 z
0 0
1 2
2 1
0 0
0
Çıxış verilənləri #1
ab
d
-

z
-