#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
#include <iomanip>
using namespace std;
typedef long long ll;

int Tmax, V, E, u, v, d, dis[444][444], Nnew, new_id, dst,order[11111],check[444],par[444];
vector<vector<pair<int, int>>> li(444);
queue<pair<int,int>> route;

void dfs(int now,int distance) {
	route.push(make_pair(now,distance));
	for (auto &e : li[now]) {
		if (par[e.first] == now) {
			dfs(e.first, e.second);
			route.push(make_pair(now, e.second));
		}
	}
}

int main() {
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		cin >> u >> v >> d;
		li[u].push_back(make_pair(v, d));
		li[v].push_back(make_pair(u, d));
		dis[u][v] = d;
		dis[v][u] = d;
	}
	cin >> Tmax;
	for (int i = 0; i < Tmax; i++) {
		cin >> Nnew;
		if (Nnew)
			cin >> new_id >> order[i];
		else
			order[i] = -1;
	}
	for (int i = 1; i <= V; i++)
		check[i] = 0;
	priority_queue<pair<pair<int, int>,int>,vector<pair<pair<int, int>,int>>,greater<pair<pair<int, int>, int >>> que;
	que.push(make_pair(make_pair(0, 1),-1));
	while (!que.empty()) {
		int now = que.top().first.second, npar=que.top().second;
		que.pop();
		if (!check[now]) {
			check[now]++;
			par[now] = npar;
			for (auto &e : li[now]) {
				int next = e.first, dnext = e.second;
				if (!check[next])
					que.push(make_pair(make_pair(dnext, next), now));
			}
		}
	}
	dfs(1,0);
	route.pop();
	int count = 0,ndst;
	for (int i = 0; i < Tmax; i++) {
		if (!count) {
			ndst = route.front().first;
			count = route.front().second;
			route.pop();
			route.push(make_pair(ndst, count));
		}
		cout << ndst << endl;
		count--;
	}
}
