#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cassert>
#include <map>
#include <algorithm>
#include <set>
using namespace std;

using i64 = long long int;
using pii = pair< int, int >;

struct XorShift {
	unsigned int x, y, z, w;
	
	XorShift() { init(); }
	XorShift(unsigned int seed) { init(seed); }
	
	void init(unsigned int seed = 88675123) { x = 123456789; y = 362436069; z = 521288629; w = seed; }
	
	void setNext() {
		unsigned int t = x ^ (x << 11);
		x = y; y = z; z = w;
		w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
	}
	
	unsigned int nextInt() { setNext(); return w; }
	unsigned int nextInt(unsigned int n) { return nextInt() % n; }
	unsigned int nextInt(unsigned int a, unsigned int b) { assert(a <= b); return a + nextInt(b - a + 1); }
	double nextDouble() { return nextInt() * (1.0 / 0xFFFFFFFFu); }
} my_random;

// v----- Input -----v
struct Edge {
	int to;
	int dist;
};

int n, m;
vector< vector< Edge > > edge;
int T_MAX;
vector< int > dst;
// ^----- Input -----^

// v----- Shortest Path Management -----v
int len_uv[402][402];
int dist_st[402][402];
int next_st[402][402];

int getLen(int u, int v) { return len_uv[u][v]; }
int getDist(int s, int t) { return dist_st[s][t]; }
int getNext(int s, int t) { return next_st[s][t]; }

void findShortestPaths() {
	struct State {
		int v;
		int dist;
		bool operator > (const State& o) const { return dist > o.dist; }
	};
	
	memset(len_uv, -1, sizeof(len_uv));
	memset(dist_st, -1, sizeof(dist_st));
	memset(next_st, -1, sizeof(next_st));
	
	for (int v=0; v<n; ++v) {
		for (const Edge& e : edge[v]) {
			len_uv[v][e.to] = e.dist;
		}
	}
	
	for (int s=0; s<n; ++s) {
		priority_queue< State, vector< State >, greater< State > > que;
		que.push(State{s, 0});
		dist_st[s][s] = 0;
		
		while (!que.empty()) {
			State sta = que.top(); que.pop();
			if (dist_st[s][sta.v] < sta.dist) continue;
			for (const Edge& e : edge[sta.v]) {
				if (dist_st[s][e.to] == -1 || dist_st[s][e.to] > sta.dist + e.dist) {
					dist_st[s][e.to] = sta.dist + e.dist;
					next_st[e.to][s] = sta.v;
					que.push(State{e.to, dist_st[s][e.to]});
				}
			}
		}
	}
}
// ^----- Shortest Path Management -----^

// v----- Utility -----v
void COMMAND_STAY(int len=1) { for (int i=0; i<len; ++i) cout << -1 << endl; }
void COMMAND_MOVE(int w, int len=1) { for (int i=0; i<len; ++i) cout << w+1 << endl; }
// ^----- Utility -----^

// v----------------------------------- Solver -----------------------------------v
vector< vector< int > > order_count;
vector< vector< int > > order_set;

int sqr(int x) { return x * x; }
int calcDeliScore(int ot, int dt) { return sqr(T_MAX) - sqr(dt - ot); }
int getCount(int v, int t1, int t2) { return order_count[v][t2] - order_count[v][t1]; }

void setup() {
	order_count.assign(n, vector< int >(T_MAX+1, 0));
	order_set.assign(n, vector< int >());
	
	for (int t=0; t<T_MAX; ++t) {
		if (dst[t] >= 0) {
			++order_count[0][t+1];
			++order_count[dst[t]][t+1];
			order_set[dst[t]].push_back(t);
		}
	}
	
	for (int v=0; v<n; ++v) {
		order_set[v].push_back(1L << 30);
		for (int t=0; t<T_MAX; ++t) {
			order_count[v][t+1] += order_count[v][t];
		}
	}
}

void beamSearch() {
	struct BeamState {
		int v, t0;
		vector< short > fin;
		int pt, pi; // link for the previous state
	};
	
	const int BEAM_WIDTH = 100;
	vector< vector< BeamState > > state(T_MAX + 1, vector< BeamState >());
	
	using Score = pair< i64, int >; // (score, index)
	vector< priority_queue< Score, vector< Score >, greater< Score > > > que(T_MAX + 1);
	
	auto updateBeam = [&](int t, const BeamState& sta, i64 score) {
		if (t > T_MAX) return false;
		int i = state[t].size();
		if (i < BEAM_WIDTH) {
			state[t].push_back(sta);
			que[t].push(Score(score, i));
			return true;
		}
		else {
			if (que[t].top().first < score) {
				i = que[t].top().second; que[t].pop();
				state[t][i] = sta;
				que[t].push(Score(score, i));
				return true;
			}
		}
		return false;
	};
	
	setup();
	state[0].push_back(BeamState{0, 0, vector< short >(n, 0), -1, -1});
	que[0].push(Score(0, 0));
	
	Score best_score(-1, -1);
	int last_t = 0;
	for (int t=0; t<=T_MAX; ++t) {
		while (!que[t].empty()) {
			Score p = que[t].top(); que[t].pop();
			
			if (best_score < p) {
				best_score = p;
				last_t = t;
			}
			
			if (t == T_MAX) continue;
			
			BeamState sta = state[t][p.second];
			
			if (sta.v == 0) { // stay
				int lb = sta.t0, ub = T_MAX;
				while (ub - lb > 1) {
					int med = (ub + lb) / 2;
					if (getCount(0, sta.t0 + 1, med + 1) > 0) ub = med;
					else lb = med; 
				}
				
				BeamState nxt_sta = sta;
				nxt_sta.t0 = ub;
				nxt_sta.pt = t;
				nxt_sta.pi = p.second;
				updateBeam(nxt_sta.t0, nxt_sta, p.first);
			}
			else { // put
				bool flag = false;
				for (int c=1; c<n; ++c) {
					if (order_set[c][sta.fin[c]] > sta.t0) continue;	
					flag |= (getDist(sta.v, 0) == getDist(sta.v, c) + getDist(c, 0));
				}
				
				if (!flag) {
					BeamState nxt_sta = sta;
					nxt_sta.v = 0;
					nxt_sta.t0 = t + getDist(sta.v, 0);
					nxt_sta.pt = t;
					nxt_sta.pi = p.second;
					updateBeam(nxt_sta.t0, nxt_sta, p.first);
				}
			}
				
			vector< int > destination;
			for (int w=1; w<n; ++w) {
				if (order_set[w][sta.fin[w]] > sta.t0) continue;	
				destination.push_back(w); // delivery
			}
			sort(destination.begin(), destination.end(),
				[&](int a, int b) {
					return getDist(sta.v, a) < getDist(sta.v, b);
				}
			);
			
			vector< int > acc;
			for (int w : destination) {
				bool flag = false;
				for (int c : acc) flag |= (getDist(sta.v, w) == getDist(sta.v, c) + getDist(c, w));
				if (flag) continue;
				acc.push_back(w);
					
				BeamState nxt_sta = sta;
				nxt_sta.v = w;
				i64 nxt_score = p.first;
				
				int i = nxt_sta.fin[w];
				while (order_set[w][i] <= nxt_sta.t0) {
					nxt_score += calcDeliScore(order_set[w][i], t);
					++i;
				}
				nxt_sta.fin[w] = i;
				
				nxt_sta.pt = t;
				nxt_sta.pi = p.second;
				updateBeam(t + getDist(sta.v, w), nxt_sta, nxt_score);
			}
		}
	}
	
	vector< int > seq_v, seq_t;
	int i = best_score.second, t = last_t;
	while (state[t][i].pi != -1) {
		BeamState sta = state[t][i];
		seq_v.push_back(sta.v);
		seq_t.push_back(t);
		t = sta.pt;
		i = sta.pi;
	}
	
	reverse(seq_v.begin(), seq_v.end());
	reverse(seq_t.begin(), seq_t.end());
	
	int cur_v = 0, cur_t = 0, step = seq_v.size();
	for (int i=0; i<step; ++i) {
		if (cur_v == seq_v[i]) {
			while (cur_t < seq_t[i]) {
				COMMAND_STAY();
				++cur_t;
			}
		}
		else {
			while (cur_v != seq_v[i]) {
				int nxt_v = getNext(cur_v, seq_v[i]);
				int len = getLen(cur_v, nxt_v);
				COMMAND_MOVE(nxt_v, len);
				cur_v = nxt_v;
				cur_t += len;
			}
		}
	}
	for (int t=last_t; t<T_MAX; ++t) COMMAND_STAY();
}

void solve() {
	beamSearch();
}
// ^----------------------------------- Solver -----------------------------------^

int main() {
	cin >> n >> m;
	edge.assign(n, vector< Edge >());
	for (int i=0; i<m; ++i) {
		int u, v, d;
		cin >> u >> v >> d;
		--u; --v;
		edge[u].push_back(Edge{v, d});
		edge[v].push_back(Edge{u, d});
	}
	findShortestPaths();
	
	cin >> T_MAX;
	dst.assign(T_MAX, -1);
	for (int i=0; i<T_MAX; ++i) {
		int N_new;
		cin >> N_new;
		for (int j=0; j<N_new; ++j) {
			int id, v;
			cin >> id >> v;
			--v;
			dst[i] = v;
		}
	}
	
	solve();
}


Measured memory_bytes: 886784