import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn = "in.txt") { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto M = RD;
	auto edges = new long[2][][](N);
	foreach (i; 0..M)
	{
		auto u = RD-1;
		auto v = RD-1;
		auto d = RD;
		edges[u] ~= [v, d];
		edges[v] ~= [u, d];
	}
	auto f = RDA;
	auto T = RD;

	auto dist = new long[][](N);
	foreach (i; 0..N)
	{
		auto dist_ = new long[](N);
		dist_[] = long.max;
		dist_[i] = 0;
		auto open = heapify!((long a, long b) => dist_[a] > dist_[b])(new long[](N), 0);
		open.insert(i);
		while (!open.empty)
		{
			auto u = open.front; open.removeFront;
			foreach (e; edges[u])
			{
				auto v = e[0];
				auto d = e[1];
				if (dist_[u]+d < dist_[v])
				{
					dist_[v] = dist_[u] + d;
					open.insert(v);
				}
			}
		}
		dist[i] = dist_;
	}
	//debug writeln("dist done");

	long[3] pos;
	long[][long] newStack, putStack;
	long newCnt, putCnt;
	bool isFile;
	debug isFile = true;

	long computeDist(long dst)
	{
		long d;
		if (pos[2] == 0)
			d = dist[pos[0]][dst];
		else
		{
			auto d1 = dist[pos[0]][dst] + pos[2];
			auto d2 = dist[pos[1]][dst] + dist[pos[0]][pos[1]] - pos[2];
			d       = min(d1, d2);
		}
		return d;
	}
	long computeExp(long dst, long elapsed)
	{
		long wait = elapsed + computeDist(dst);
		return T^^2 - wait;
	}
	long[] computeBestDst(long time)
	{
		long score, dst;
		foreach (key; putStack.keys)
		{
			long s;
			foreach (e; putStack[key])
				s += computeExp(key, time-e);
			if (s > score)
			{
				score = s;
				dst   = key;
			}
		}
		return [score, dst];
	}
	
	long lastW;
	foreach (i; 0..T)
	{
		auto N1 = RD;
		foreach (_; 0..N1)
		{
			auto id = RD;
			auto dst = RD-1;
			newStack[dst] ~= i;
		}
		newCnt += N1;
		auto N2 = RD;
		foreach (_; 0..N2) auto id = RD;

		if (pos[2] == 0)
		{
			if (pos[0] == 0)
			{
				foreach (key; newStack.keys)
					putStack[key] ~= newStack[key];
				long[][long] dummy;
				newStack = dummy;
				putCnt += newCnt;
				newCnt = 0;
			}
			else
			{
				putCnt -= putStack.get(pos[0], []).length;
				putStack.remove(pos[0]);
			}
		}

		double stackRatio = 10000.0;
		if (putCnt != 0)
			stackRatio = cast(double)newCnt / putCnt / 15.0;
		auto recallExp = stackRatio^^2;
		auto recallD   = computeDist(0);
		if (recallD != 0)
			recallExp = (1.0 / recallD) * stackRatio;

		auto keys = putStack.keys;
		auto expList = new double[](keys.length);
		foreach (j; 0..keys.length)
		{
			auto v = keys[j];
			expList[j] = (1.0 / (cast(double)computeDist(v) / putStack[v].length)) + (1.0 / dist[v][0]) * stackRatio;
		}
		auto p = expList.MIN_POS!"a > b";
		long dst;
		if (!keys.empty)
			if (expList[p] > recallExp)
				dst = keys[p];

		long w;
		if (pos[0] == dst)
			w = -1;
		else if (pos[2] != 0)
		{
			auto d1 = dist[pos[0]][dst] + pos[2];
			auto d2 = dist[pos[1]][dst] + dist[pos[0]][pos[1]] - pos[2];
			if (d1 < d2)
				w = pos[0];
			else
				w = pos[1];
		}
		else
		{
			long best = long.max;
			foreach (e; edges[pos[0]])
			{
				auto d = e[1] + dist[e[0]][dst];
				if (d < best)
				{
					best = d;
					w = e[0];
				}
			}
			pos[1] = w;
		}
		if (w != -1)
		{
			if (w == pos[1])
				++pos[2];
			else
				--pos[2];
			if (pos[2] == dist[pos[0]][pos[1]])
			{
				pos[0] = pos[1];
				pos[2] = 0;
			}
		}

		//stderr.writeln("i:", i, " ", pos);
		writeln(w == -1 ? w : w+1);
		stdout.flush();
		auto verdict = RD!string;
		if (verdict == "NG")
		{
			//stderr.writeln(edges[pos[0]]);
			break;
		}
		auto N3 = RD;
		foreach (_; 0..N3) auto id = RD;
	}

	stdout.flush();
	//debug readln();
}

Measured memory_bytes: 9676