#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, Nnew, new_id, dst, order[11111], check[444], par[444], sum = 0;
vector<vector<pair<int, int>>> li(444);
queue<pair<int, int>> route;
queue<int> store;
queue<int> car;

void dfs(int now, int distance) {
	route.push(make_pair(now, distance));
	sum += distance * 2;
	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));
	}
	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=1, check_store = 1;
	for (int i=0; i < Tmax; i++) {
		if (order[i] > 0)
			store.push(order[i]);
		if (ndst == 1 && !count)
			check_store = 1;
		if (check_store) {
			while (!store.empty()) {
				car.push(store.front());
				store.pop();
			}
		}
		if (check_store&&car.size() < 10)
			cout << "-1" << endl;
		else {
			check_store = 0;
			if (!count) {
				queue<int> keep;
				while (!car.empty()) {
					if (car.front() != ndst)
						keep.push(car.front());
					car.pop();
				}
				while (!keep.empty()) {
					car.push(keep.front());
					keep.pop();	
				}
				int nowp = ndst;
				ndst = route.front().first;
				count = route.front().second;
				route.pop();
				route.push(make_pair(ndst, count));
				if (car.empty()) {
					while (ndst != par[nowp]) {
						ndst = route.front().first;
						count = route.front().second;
						route.pop();
						route.push(make_pair(ndst, count));
					}
				}
			}
			cout << ndst << endl;
			count--;
		}
	}
}
