eolymp
bolt
Try our new interface for solving problems
Problems

The product of graphs

The product of graphs

Given a directed acyclic graph. Standard game on a graph is as follows: initially at one of the vertices of the graph (we call it the starting point) should feature. Two players take turns moving her in the ribs. Plays one who can not make a move. In game theory is often considered more complex games. For example, the direct product of two games on graphs. The direct product of games - it's the next game: at the beginning of each graph is the starting position on the chip. Over the course of the player moves along the edges of both pieces (each piece moves in its own box). Plays one who can not make a move. That is the one who can not make a move at least one game. Your task - to determine who will benefit from the proper game. \InputFile The first line will be given numbers \textbf{N_1} and \textbf{M_1} - the number of vertices and edges in the first column (\textbf{1} ≤ \textbf{N_1}, \textbf{M_1} ≤ \textbf{100000}). In the following lines \textbf{M_1} contains two numbers \textbf{x} and \textbf{y} (\textbf{1} ≤ \textbf{x}, \textbf{y} ≤ \textbf{N_1}). The following lines set \textbf{M_2+1} second graph in the same format. Ends the input file list of pairs of initial vertices for which you want to solve the problem. On the first line number is set to \textbf{T} (\textbf{1} ≤ \textbf{T} ≤ \textbf{100000}) - initial number of pairs of vertices. In the following \textbf{T} lines are pairs of vertices \textbf{v_1} and \textbf{v_2} (\textbf{1} ≤ \textbf{v_1} ≤ \textbf{N_1}, \textbf{1} ≤ \textbf{v_2} ≤ \textbf{N_2}). \OutputFile On each of the pairs of \textbf{T} output the line of initial vertices "\textbf{first}", if correct wins first game, and "\textbf{second}", if the second one.
Time limit 2 seconds
Memory limit 256 MiB
Input example #1
3 2
1 2
2 3
2 1
1 2
2
2 1
3 2
Output example #1
first
second