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

struct SegTree(T)
{
	T delegate(const(T), const(T)) f;
	T[] data;
	T init;
    this(T[] _data, T delegate(const(T), const(T)) _f, T _init)
    {
		f = _f; init = _init;
		size_t n = 1; while (n < _data.length) n *= 2; data.length = n*2-1;
		foreach (i; 0.._data.length) data[i+n-1] = _data[i];
		foreach (i; _data.length..n) data[i+n-1] = _init;
		foreach_reverse (i; 0..n-1) data[i] = f(data[i*2+1], data[i*2+2]);
	}
    T query(size_t l, size_t r) const
	{
        size_t n = (data.length+1) / 2; l += n-1; r += n-1; T res = f(init, data[l]);
        while (l < r)
		{
            if ((l & 1) == 0) res = f(res, data[l]);
            if ((r & 1) == 0) res = f(res, data[r-1]);
            l = l/2; r = (r-1)/2;
        }
        return res;
    }
	void update(size_t i, T v)
	{
		if (v <= data[i]) return;
		i += (data.length+1) / 2 - 1; data[i] = v;
		while (i != 0) { i = (i-1)/2; data[i] = f(data[i*2+1], data[i*2+2]); }
    }
}

void main()
{
	debug file_io();
	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_;
	}
	debug writeln("dist done");

	void farSort(ref long[] arr)
	{
		arr.sort!((long a, long b) => dist[0][a] > dist[0][b])();
	}
	void nearSort(ref long[] arr)
	{
		arr.sort!((long a, long b) => dist[0][a] < dist[0][b])();
	}
	void nearestSort(ref long[] arr)
	{
		long l;
		long pos;
		if (arr.length > 100)
		{
			nearSort(arr);
			l = arr.length - 100;
			pos = arr[l-1];
		}
		foreach (i; l..arr.length)
		{
			auto p = arr[i..$].MIN_POS!((long a, long b) => dist[pos][a] < dist[pos][b]);
			swap(arr[i], arr[i+p]);
			pos = arr[i];
		}
	}
	long[] delivery(long startTime, in long[][long] stack)
	{
		auto dsts = stack.keys;
		nearestSort(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;
		nearestSort(dsts);
		dsts ~= 0;
		long lastPos;
		long[] command;
		foreach (dst; dsts)
		{
			auto d = new long[](N);
			d[] = long.max;
			d[lastPos] = 0;
			auto open = heapify!((long a, long b) => d[a] > d[b])(new long[](N), 0);
			open.insert(lastPos);
			auto prev = new long[](N);
			while (!open.empty)
			{
				auto u = open.front; open.removeFront;
				if (u == dst) break;
				foreach (e; edges[u])
				{
					auto v = e[0];
					auto c = e[1];
					if (d[u]+c < d[v])
					{
						d[v] = d[u] + c;
						prev[v] = u;
						open.insert(v);
					}
				}
			}
			long[] tmpCmd;
			long pos = dst;
			while (pos != lastPos)
			{
				auto u = prev[pos];
				auto v = pos;
				pos    = u;
				foreach (i; 0..dist[u][v])
					tmpCmd ~= v+1;
			}
			tmpCmd.reverse();
			command ~= tmpCmd;
			lastPos = dst;
		}
		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;
	}
	debug writeln("lastTime done");*/

	auto dp = new long[][long][](T*2);
	{
		dp[0][0] = [0];
		auto st     = SegTree!(long)(new long[](T), (const long a, const long b) => max(a, b), 0);
		auto stack  = new long[][long][](T);
		auto time_r = new long[](T);
		foreach (i; 0..time_r.length) time_r[i] = i;
		foreach (i; 0..T)
		{
			debug if (i % 10 == 0) writeln("i:", i, " keys:", dp[i].keys.length);
			foreach (key; dp[i].keys)
			{
				auto s = dp[i][key][0];
				if (info[i].empty)
				{
					if (s > dp[i+1].get(key, [-1])[0])
					{
						dp[i+1][key] = dp[i][key];
						st.update(i+1, s);
					}
					continue;
				}
				foreach (j; time_r[key]..i+1)
				{
					foreach (e; info[j])
						stack[key][e] ~= j;
				}
				time_r[key] = i+1;
				auto r = delivery(i, stack[key]);
				if (r[1] <= 0 || r[0] > T) continue;
				if (s > dp[i+1].get(key, [-1])[0])
				{
					if (s >= st.query(0, i+1))
					{
						dp[i+1][key] = dp[i][key];
						st.update(i+1, s);
					}
				}
				s += r[1];
				if (s > dp[r[0]].get(i+1, [-1])[0])
				{
					if (s > st.query(0, r[0]))
					{
						dp[r[0]][i+1] = [s] ~ dp[i][key][1..$] ~ i;
						st.update(r[0], s);
					}
				}
			}
		}
	}
	debug writeln("dp done");

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

	long[] command;
	{
		auto startTimes = dp[T][pos][1..$];
		long[][long] stack;
		foreach (i; 0..T)
		{
			if (startTimes.empty) break;
			foreach (e; info[i])
				stack[e] ~= i;
			if (i == startTimes.front)
			{
				command ~= computeCommand(stack);
				startTimes.popFront;
				long[][long] dummy;
				stack = dummy;
			}
			else if (command.length <= i)
			{
				command ~= -1;
			}
		}
		while (command.length < T)
			command ~= -1;
	}
	debug writeln("command done");

	bool isFile;
	debug isFile = true;
	if (isFile)
	{
		auto f = File("out.txt", "w");
		foreach (e; command)
			f.writeln(e);
		debug writeln("complete");
	}
	else
	{
		foreach (e; command)
			writeln(e);
	}
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 179708