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) { _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 T = RD;
	auto info = new long[][](T);
	foreach (i; 0..T)
	{
		auto Q = RD;
		foreach (j; 0..Q)
		{
			auto id = RD;
			info[i] ~= RD-1;
		}
	}

	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_;
	}

	void farSort(ref long[] arr)
	{
		arr.sort!((long a, long b) => dist[0][a] > dist[0][b])();
	}
	long[] delivery(long startTime, in long[][long] stack)
	{
		auto dsts = stack.keys;
		farSort(dsts);
		long lastPos, dTime = startTime, score;
		foreach (dst; dsts)
		{
			dTime += dist[lastPos][dst];
			foreach (oTime; stack[dst])
				score += T^^2 - (dTime - oTime)^^2;
			lastPos = dst;
		}
		dTime += dist[lastPos][0];
		return [dTime, score];
	}
	long[] computeCommand(in long[][long] stack)
	{
		auto dsts = stack.keys;
		farSort(dsts);
		long lastPos;
		long[] command;
		foreach (dst; dsts)
		{
			foreach (i; 0..dist[lastPos][dst])
				command ~= dst+1;
			lastPos = dst;
		}
		foreach (i; 0..dist[lastPos][0])
			command ~= 1;
		return command;
	}

	long lastTime;
	{
		long[] lastInfo;
		foreach_reverse (i; 0..T)
		{
			if (info[i].empty) continue;
			lastInfo = info[i].dup;
			break;
		}
		farSort(lastInfo);
		long elapsed, pos;
		foreach (e; lastInfo)
		{
			elapsed += dist[pos][e];
			pos = e;
		}
		elapsed += dist[pos][0];
		lastTime = T - elapsed + 1;
	}

	auto dp = new long[][long][](T*2);
	dp[0][0] = [0];
	foreach (i; 0..T)
	{
		foreach (key; dp[i].keys)
		{
			dp[i+1][key] = dp[i][key];
			auto s = dp[i][key][0];
			long[][long] stack;
			foreach (k; key..i+1)
			{
				foreach (e; info[k])
					stack[e] ~= k;
			}
			auto r = delivery(i, stack);
			s += r[1];
			if (s > dp[r[0]].get(i+1, [-1])[0])
				dp[r[0]][i+1] = [s] ~ dp[i][key][1..$] ~ i;
		}
	}

	long pos, best;
	foreach (key; dp[T].keys)
	{
		if (dp[T][key][0] > best)
		{
			pos = key;
			best = dp[T][key][0];
		}
	}

	auto startTimes = dp[T][pos][1..$];
	long[][long] stack;
	long[] command;
	foreach (i; 0..T)
	{
		if (startTimes.empty) break;
		foreach (e; info[i])
			stack[e] ~= i;
		if (i == startTimes.front)
		{
			command ~= computeCommand(stack);
		}
		else
		{
			command ~= -1;
		}
	}

	foreach (e; command)
		writeln(e);
	stdout.flush();
	debug readln();
}