using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Link
{
public int n1;
public int n2;
public Link(int n1, int n2)
{
this.n1 = n1;
this.n2 = n2;
}
}
class Player
{
static void Main(string[] args)
{
string[] inputs;
inputs = Console.ReadLine().Split(' ');
int N = int.Parse(inputs[0]); // the total number of nodes in the level, including the gateways
int L = int.Parse(inputs[1]); // the number of links
int E = int.Parse(inputs[2]); // the number of exit gateways
int EI = 0;
List<Link> links = new List<Link>();
List<int> exits = new List<int>();
for (int i = 0; i < L; i++)
{
inputs = Console.ReadLine().Split(' ');
int N1 = int.Parse(inputs[0]); // N1 and N2 defines a link between these nodes
int N2 = int.Parse(inputs[1]);
Link newLink = new Link(N1, N2);
links.Add(newLink);
}
for (int i = 0; i < E; i++)
{
EI = int.Parse(Console.ReadLine()); // the index of a gateway node
exits.Add(EI);
}
// game loop
while (true)
{
int SI = int.Parse(Console.ReadLine()); // The index of the node on which the Bobnet agent is positioned this turn
string cut = null;
bool wasCut = false;
for (int i = 0; i < links.Count; i++)
{
if ((links[i].n1 == SI && exits.Contains(links[i].n2)) || (links[i].n2 == SI && exits.Contains(links[i].n1)))
{
if (links[i].n2 == SI)
{
cut = SI.ToString() + " " + links[i].n1.ToString();
links.Remove(links[i]);
wasCut = true;
break;
}
else
{
cut = SI.ToString() + " " + links[i].n2.ToString();
links.Remove(links[i]);
wasCut = true;
break;
}
}
}
if (!wasCut)
{
foreach (Link l in links)
{
if ((exits.Contains(l.n2) || exits.Contains(l.n1)) && l.cut == false)
{
cut = l.n1.ToString() + " " + l.n2.ToString();
links.Remove(l);
}
}
}
foreach (int e in exits)
{
Console.Error.WriteLine(SI + " " + e);
}
// Example: 0 1 are the indices of the nodes you wish to sever the link between
Console.WriteLine(cut);
}
}
}
}