#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(const auto &buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

//========================================================================//

class Timestamp {
private:
	enum timestamp_t {
		BEGIN, END, PAUSE
	};
	std::chrono::system_clock::time_point start, finish;
	timestamp_t mode;
	double elapsed;
public:
	Timestamp() {
		mode = END;
		elapsed = 0;
	}
	void begin() {
		if (mode == BEGIN) {
			std::cout << "timestamp mode error with BEGIN -> BEGIN" << std::endl;
			exit(EXIT_SUCCESS);
		}
		mode = BEGIN;
		start = std::chrono::system_clock::now();
	}
	void pause() {
		finish = std::chrono::system_clock::now();
		if (mode == PAUSE) {
			std::cout << "timestamp mode error with PAUSE -> PAUSE" << std::endl;
			exit(EXIT_SUCCESS);
		}
		if (mode == END) {
			std::cout << "timestamp mode error with END -> PAUSE" << std::endl;
			exit(EXIT_SUCCESS);
		}
		elapsed += double(std::chrono::duration_cast<std::chrono::nanoseconds>(finish - start).count());
		mode = PAUSE;
	}
	double end() {
		finish = std::chrono::system_clock::now();
		double ret = 0;
		if (mode == END) {
			std::cout << "timestamp mode error with END -> END" << std::endl;
			exit(EXIT_SUCCESS);
		}
		if (mode == PAUSE) {
			ret = elapsed / 1e6;
			elapsed = 0;
		}
		else {
			elapsed += double(std::chrono::duration_cast<std::chrono::nanoseconds>(finish - start).count());
			ret = elapsed / 1e6;
			elapsed = 0;
		}
		mode = END;
		return ret;
	}
	double check() {
		if (mode == BEGIN) {
			std::chrono::system_clock::time_point cur = std::chrono::system_clock::now();
			return double(std::chrono::duration_cast<std::chrono::nanoseconds>(cur - start).count()) / 1e6;
		}
		else {
			return elapsed / 1e6;
		}
	}
};

void Warshallfloyd(vvi &table, vvi &route) {
	int n = int(table.size());
	Loop(i, n) table[i][i] = 0;
	route = vvi(n, vi(n));
	Loop(i, n) {
		Loop(j, n) {
			route[i][j] = j;
		}
	}
	Loop(k, n) {
		Loop(i, n) {
			Loop(j, n) {
				if (table[i][k] == INT_MAX || table[k][j] == INT_MAX) continue;
				if (table[i][k] + table[k][j] < table[i][j]) {
					table[i][j] = table[i][k] + table[k][j];
					route[i][j] = route[i][k];
				}
			}
		}
	}
}

ll twice(ll x) {
	return x * x;
}

//========================================================================//

struct node_t {
	int id;
	vi nbrs;
	vi eids;
};

struct edge_t {
	int id;
	int s, t;
	int d;
};

struct graph_t {
	int n, m;
	vector<node_t> nodes;
	vector<edge_t> edges;
	vvi table;
	vvi route;
};

struct order_t {
	int id;
	int dst_nid;
	int ord_time;
};

struct orderlist_t {
	int T_max;
	int T_last;
	vector<vector<order_t>> orders;
};

struct localtime_t {
	int cur;
	int rem;
	int lastput;
};

struct initparam_t {
	size_t SAVE_NUM;
	int ALTERNATIVE_INTERVAL;
	int SHORT_SPAN;
	int LONG_SPAN;
	int QUICK_START;
};

namespace Trie {

	struct trienode_t {
		int val; map<int, trienode_t*> childs_mp; int deg; trienode_t *parent_node;
		vi local_cmds; vector<order_t> rem_ords; ll score_sum;
	};

	trienode_t *root;

	void init_trie() {
		root = new trienode_t;
		root->deg = 0;
		root->parent_node = nullptr;
		root->score_sum = 0;
	}

	// vals[0, last_id) exists, and return the last node
	void find_prefix(const vi &vals, trienode_t *last_node, int &last_id) {
		last_node = root;
		for (; last_id < int(vals.size()); ++last_id) {
			int v = vals[last_id];
			auto itr = last_node->childs_mp.find(v);
			if (itr == last_node->childs_mp.end()) {
				return;
			}
			else {
				last_node = itr->second;
			}
		}
	}
	trienode_t* add(trienode_t *parent_node, const int val, const vi &local_cmds, const vector<order_t> &rem_ords, const ll score_sum) {
		parent_node->childs_mp[val] = new trienode_t;
		trienode_t *ret_node = parent_node->childs_mp[val];
		ret_node->val = val;
		ret_node->deg = parent_node->deg + 1;
		ret_node->parent_node = parent_node;
		ret_node->local_cmds = local_cmds;
		ret_node->rem_ords = rem_ords;
		ret_node->score_sum = score_sum;
		return ret_node;
	}
	void erase(trienode_t *node) {
		if (node == root) return;
		Loopitr(itr, node->childs_mp) {
			erase(itr->second);
		}
		node->parent_node->childs_mp.erase(node->val);
		delete(node);
	}
};

//========================================================================//

void input(graph_t &G, orderlist_t &ordlst) {

	cin >> G.n >> G.m;
	G.nodes.resize(G.n);
	Loop(i, G.n) {
		G.nodes[i].id = i;
	}
	G.edges.resize(G.m);
	Loop(i, G.m) {
		G.edges[i].id = i;
	}
	G.table = vvi(G.n, vi(G.n, INT_MAX));
	Loop(i, G.m) {
		int s, t; cin >> s >> t; s--; t--;
		int d; cin >> d;
		G.edges[i].s = s;
		G.edges[i].t = t;
		G.edges[i].d = d;
		G.nodes[s].nbrs.push_back(t);
		G.nodes[s].eids.push_back(i);
		G.nodes[t].nbrs.push_back(s);
		G.nodes[t].eids.push_back(i);
		G.table[s][t] = d;
		G.table[t][s] = d;
	}
	Warshallfloyd(G.table, G.route);
	cin >> ordlst.T_max;
	ordlst.orders.resize(ordlst.T_max);
	Loop(i, ordlst.T_max) {
		int N_new; cin >> N_new;
		Loop(_, N_new) {
			order_t order;
			cin >> order.id;
			cin >> order.dst_nid; order.dst_nid--;
			order.ord_time = i;
			ordlst.orders[i].push_back(order);
			ordlst.T_last = i;
		}
	}
}

void output(const vector<int> &cmds) {
	Loop(i, cmds.size()) {
		cout << cmds[i] << endl;
	}
}

Timestamp ts;

//

void heuristic_master(const graph_t &G, const orderlist_t &ordlst, vector<int> &ans);
ll solve_mid_localstep(const graph_t &G, vector<order_t> &ords, vector<int> &cmds, const orderlist_t &ordlst, localtime_t &T);
ll solve_last_localstep(const graph_t &G, vector<order_t> &ords, vector<int> &cmds, const orderlist_t &ordlst, localtime_t &T);

//

int main() {

	quickio();

	ts.begin();

	graph_t G;
	orderlist_t ordlst;
	vector<int> ans;
	Trie::init_trie();

	input(G, ordlst);

	heuristic_master(G, ordlst, ans);
	output(ans);

}

//========================================================================//

void solve_init(const graph_t &G, const orderlist_t &ordlst, set<pair<ll, Trie::trienode_t*>> &solution_set, initparam_t params) {
	vector<order_t> rem_ords;
	Trie::trienode_t *trie_ptr = Trie::root;
	ll score_sum = 0;
	localtime_t T;
	T.lastput = 0;
	int alternative_counter = 0;
	bool waiting_for_last_ord = false;
	for (T.cur = 0; T.cur < ordlst.T_max;) {
		if (T.cur >= ordlst.T_last) {
			T.rem = ordlst.T_max - T.cur;
			vector<int> cmds;
			localtime_t T_bckup = T;
			score_sum += solve_last_localstep(G, rem_ords, cmds, ordlst, T);
			int dT = T.cur - T_bckup.cur;
			trie_ptr = Trie::add(trie_ptr, dT, cmds, rem_ords, score_sum);
		}
		else if (rem_ords.size() < params.SAVE_NUM) {
			localtime_t T_bckup = T;
			for (int xt = T.cur + 1; xt <= ordlst.T_last && rem_ords.size() < params.SAVE_NUM; ++xt) {
				Foreach(ord, ordlst.orders[xt]) {
					rem_ords.push_back(ord);
				}
				T.lastput = xt;
			}
			T.cur = T.lastput;
			int dT = T.cur - T_bckup.cur;
			trie_ptr = Trie::add(trie_ptr, dT, { -dT }, rem_ords, score_sum);
		}
		else if (waiting_for_last_ord) {
			localtime_t T_bckup = T;
			for (int xt = T.cur + 1; xt <= ordlst.T_last; ++xt) {
				Foreach(ord, ordlst.orders[xt]) {
					rem_ords.push_back(ord);
				}
				T.lastput = xt;
			}
			T.cur = T.lastput;
			int dT = T.cur - T_bckup.cur;
			trie_ptr = Trie::add(trie_ptr, dT, { -dT }, rem_ords, score_sum);
			waiting_for_last_ord = false;
		}
		else {
			alternative_counter += 1;
			alternative_counter %= params.ALTERNATIVE_INTERVAL;
			if (params.QUICK_START && rem_ords.size() <= params.SAVE_NUM) {
				T.rem = int(rem_ords.size()) * 7;
			}
			else if (T.cur < ordlst.T_last - params.LONG_SPAN) {
				if (alternative_counter == 0) T.rem = params.LONG_SPAN;
				else T.rem = params.SHORT_SPAN;
			}
			else {
				T.rem = ordlst.T_last - T.cur;
				waiting_for_last_ord = true;
			}
			vector<int> cmds;
			localtime_t T_bckup = T;
			score_sum += solve_mid_localstep(G, rem_ords, cmds, ordlst, T);
			int dT = T.cur - T_bckup.cur;
			if (dT > 0) {
				trie_ptr = Trie::add(trie_ptr, dT, cmds, rem_ords, score_sum);
			}
			else {
				for (int xt = T.cur + 1; xt <= ordlst.T_last; ++xt) {
					Foreach(ord, ordlst.orders[xt]) {
						rem_ords.push_back(ord);
					}
					T.lastput = xt;
					if (ordlst.orders[xt].size()) break;
				}
				T.cur = T.lastput;
				int dT = T.cur - T_bckup.cur;
				trie_ptr = Trie::add(trie_ptr, dT, { -dT }, rem_ords, score_sum);
			}
		}
	}
	/*
	Foreach(ord, rem_ords) {
		cerr << ord.id << " " << ord.dst_nid << " " << ord.ord_time << endl;
	}
	*/
	solution_set.insert({ score_sum, trie_ptr });
}

vector<int> get_ans(const graph_t &G, Trie::trienode_t* node) {
	vector<int> ans;
	stack<int> stk;
	while (node != Trie::root) {
		Loopr(i, node->local_cmds.size()) {
			stk.push(node->local_cmds[i]);
		}
		node = node->parent_node;
	}
	int cur_nid = 0;
	while (stk.size()) {
		int x = stk.top(); stk.pop();
		if (x < 0) {
			Loop(_, -x) {
				ans.push_back(-1);
			}
		}
		else {
			while (cur_nid != x) {
				int next_nid = G.route[cur_nid][x];
				Loop(_, G.table[cur_nid][next_nid]) {
					ans.push_back(next_nid + 1);
				}
				cur_nid = next_nid;
			}
		}
	}
	return ans;
}

// Search step1: master program of heuristics
void heuristic_master(const graph_t &G, const orderlist_t &ordlst, vector<int> &ans) {
	Trie::root->val = 0;
	Trie::root->rem_ords = ordlst.orders[0];
	set<pair<ll, Trie::trienode_t*>> solution_set;
	Foreach(save_num, vi({10, 20})) {
		Foreach(alternative_interval, vi({2, 3})) {
			Foreach(short_span, vi({50, 100, 150})) {
				Foreach(long_span, vi({600, 700, 800, 900, 1000})) {
					Foreach(quick_start, vi({0, 1})) {
						initparam_t params;
						params.SAVE_NUM = save_num;
						params.ALTERNATIVE_INTERVAL = alternative_interval;
						params.SHORT_SPAN = short_span;
						params.LONG_SPAN = long_span;
						params.QUICK_START = quick_start;
						solve_init(G, ordlst, solution_set, params);
					}
				}
			}
		}
	}
	ans = get_ans(G, solution_set.rbegin()->snd);
	/*
	while (ts.check() < 25000.0) {

	}
	*/
}

ll TOTAL_SCORE = 0;

ll move_next(const graph_t &G, int &cur_nid, int dst_nid, vector<vector<order_t>> &ords_per_dst, vector<int> &cmds, const orderlist_t &ordlst, localtime_t &T) {
	const ll T_max2 = twice(ordlst.T_max);
	ll score = 0;
	while (cur_nid != dst_nid) {
		int next_nid = G.route[cur_nid][dst_nid];
		T.cur += G.table[cur_nid][next_nid];
		T.rem -= G.table[cur_nid][next_nid];
		if (next_nid == 0) {
			for (int xt = T.lastput + 1; xt <= T.cur; ++xt) {
				Foreach(ord, ordlst.orders[xt]) {
					ords_per_dst[ord.dst_nid].push_back(ord);
				}
			}
			T.lastput = T.cur;
		}
		else if (ords_per_dst[next_nid].size()) {
			Foreach(ord, ords_per_dst[next_nid]) {
				score += T_max2 - twice(T.cur - ord.ord_time);
			}
			ords_per_dst[next_nid].clear();
		}
		cmds.push_back(next_nid);
		cur_nid = next_nid;
	}
	TOTAL_SCORE += score;
	return score;
}

void put_orders(vector<order_t> &ords, const vector<vector<order_t>> &ords_per_dst) {
	ords.clear();
	Loop(i, ords_per_dst.size()) {
		Foreach(ord, ords_per_dst[i]) {
			ords.push_back(ord);
		}
	}
}

ll calc_mid_evalfunc(const graph_t &G, int cur_nid, int next_nid, const vector<vector<order_t>> &ords_per_dst, const orderlist_t &ordlst, localtime_t T) {
	const ll T_max2 = twice(ordlst.T_max);
	ll eval = 0;
	T.cur += G.table[cur_nid][next_nid];
	T.rem -= G.table[cur_nid][next_nid];
	Foreach(ord, ords_per_dst[next_nid]) {
		eval += T_max2 - twice(T.cur - ord.ord_time);
	}
	Loop(i, G.n) {
		if (i == next_nid) continue;
		int next_T = T.cur + G.table[next_nid][i];
		if (G.table[next_nid][i] + G.table[i][0] <= T.rem) {
			Foreach(ord, ords_per_dst[i]) {
				eval += T_max2 - twice(next_T - ord.ord_time);
			}
		}
		else {
			Foreach(ord, ords_per_dst[i]) {
				eval += -twice(next_T - ord.ord_time);
			}
		}
	}
	return eval;
}

// Local step: send orders as possible in time T (begin from 0 and end at 0), return score
ll solve_mid_localstep(const graph_t &G, vector<order_t> &ords, vector<int> &cmds, const orderlist_t &ordlst, localtime_t &T) {
	vector<vector<order_t>> ords_per_dst(G.n);
	Foreach(ord, ords) {
		ords_per_dst[ord.dst_nid].push_back(ord);
	}
	int cur_nid = 0;
	ll score = 0;
	while (T.rem > 0) {
		int best_next_nid = -1;
		ll best_eval = LLONG_MIN;
		map<int, vi> mp;
		Loop(next_cand_nid, G.n) {
			if (ords_per_dst[next_cand_nid].size()) {
				mp[G.table[cur_nid][next_cand_nid]].push_back(next_cand_nid);
			}
		}
		int cnt = 0;
		Loopitr(itr, mp) {
			Foreach(next_cand_nid, itr->snd) {
				if (itr->fst + G.table[next_cand_nid][0] <= T.rem) {
					ll eval = calc_mid_evalfunc(G, cur_nid, next_cand_nid, ords_per_dst, ordlst, T);
					if (eval > best_eval) {
						best_next_nid = next_cand_nid;
						best_eval = eval;
					}
					cnt++;
				}
			}
			if (cnt >= 1) break;
		}
		if (best_next_nid == -1) break;
		score += move_next(G, cur_nid, best_next_nid, ords_per_dst, cmds, ordlst, T);
	}
	if (cmds.size()) {
		score += move_next(G, cur_nid, 0, ords_per_dst, cmds, ordlst, T);
	}
	put_orders(ords, ords_per_dst);
	return score;
}

ll calc_last_evalfunc(const graph_t &G, int cur_nid, int next_nid, const vector<vector<order_t>> &ords_per_dst, const orderlist_t &ordlst, localtime_t T) {
	const ll T_max2 = twice(ordlst.T_max);
	ll eval = 0;
	T.cur += G.table[cur_nid][next_nid];
	T.rem -= G.table[cur_nid][next_nid];
	Foreach(ord, ords_per_dst[next_nid]) {
		eval += T_max2 - twice(T.cur - ord.ord_time);
	}
	Loop(i, G.n) {
		if (i == next_nid) continue;
		int next_T = T.cur + G.table[next_nid][i];
		if (G.table[next_nid][i] <= T.rem) {
			Foreach(ord, ords_per_dst[i]) {
				eval += T_max2 - twice(next_T - ord.ord_time);
			}
		}
	}
	return eval;
}

// Local step: send orders as possible in time T (begin from 0 and end at 0), return score
ll solve_last_localstep(const graph_t &G, vector<order_t> &ords, vector<int> &cmds, const orderlist_t &ordlst, localtime_t &T) {
	vector<vector<order_t>> ords_per_dst(G.n);
	Foreach(ord, ords) {
		ords_per_dst[ord.dst_nid].push_back(ord);
	}
	int cur_nid = 0;
	ll score = 0;
	while (T.rem > 0) {
		int best_next_nid = -1;
		ll best_eval = LLONG_MIN;
		map<int, vi> mp;
		Loop(next_cand_nid, G.n) {
			if (ords_per_dst[next_cand_nid].size()) {
				mp[G.table[cur_nid][next_cand_nid]].push_back(next_cand_nid);
			}
		}
		int cnt = 0;
		Loopitr(itr, mp) {
			Foreach(next_cand_nid, itr->snd) {
				if (itr->fst <= T.rem) {
					ll eval = calc_last_evalfunc(G, cur_nid, next_cand_nid, ords_per_dst, ordlst, T);
					if (eval > best_eval) {
						best_next_nid = next_cand_nid;
						best_eval = eval;
					}
					cnt++;
				}
			}
			if (cnt >= 1) break;
		}
		if (best_next_nid == -1) break;
		score += move_next(G, cur_nid, best_next_nid, ords_per_dst, cmds, ordlst, T);
	}
	if (T.rem > 0) {
		cmds.push_back(-T.rem);
		T.cur += T.rem;
		T.rem -= T.rem;
	}
	put_orders(ords, ords_per_dst);
	return score;
}

Measured memory_bytes: 27420