P2017 [USACO09DEC] Dizzy Cows G

Description

The cows have taken to racing each other around the farm but they get very dizzy when running in circles, and everyone knows that dizzy cows don't produce any milk. Farmer John wants to convert all of the two-way cow paths in the farm to one-way paths in order to eliminate any 'cycles' and prevent the cows from getting dizzy. A 'cycle' enables a cow to traverse one or more cow paths and arrive back at her starting point, thus completing a loop or circle. The farm comprises N pastures (1

Input Format

Line 1: Three space separated integers: N, M1, and M2 Lines 2..1+M1: Line i+1 describes a one-way cow path using two space separated integers: A_i and B_i Lines 2+M1..1+M1+M2: Line i+M1+1 describes a two-way cow path using two space separated integers: X_i and Y_i

Output Format

Lines 1..M2: Line i should contain two space-separated integers: either X_i and Y_i or Y_i and X_i, depending on the direction assigned to the i-th two-way path. The two-way paths must appear in the same order in the output as they do in the input. If there is no solution, output "-1" on a single line.