#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, Nput, Nachieve, new_id, dst, order[11111], f[444], check[444], par[444], sum = 0, trush;
char s[3];
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));
	}
	for (int i = 1; i <= V; i++)
		cin >> f[i];
	cin >> Tmax;
	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;
	queue<int> keep;
	queue<pair<int, int>> keep2;
	for (int i = 0; i < Tmax; i++) {
		cin >> Nnew;
		if (Nnew) {
			cin >> new_id >> order[i];
			store.push(order[i]);
		}
		cin >> Nput;
		for (int j = 0; j < Nput; j++)
			cin >> trush;
		if (ndst == 1 && !count)
			check_store = 1;
		if (check_store) {
			while (!store.empty()) {
				car.push(store.front());
				store.pop();
			}
		}
		if (check_store&&car.size() < 1)
			cout << "-1" << endl;
		else {
			check_store = 0;
			if (!count) {
				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,flag=0;
				while (1) {
					int checkp = route.front().first;
					if (checkp == par[nowp])
						break;
					keep2.push(route.front());
					route.pop();
					while (!car.empty()) {
						if (car.front() == checkp) {
							flag = 1;
							break;
						}
						keep.push(car.front());
						car.pop();
					}
					while (!keep.empty()) {
						car.push(keep.front());
						keep.pop();
					}
					if (checkp == nowp) {
						if (flag) {
							while (!route.empty()) {
								keep2.push(route.front());
								route.pop();
							}
							while (!keep2.empty()) {
								route.push(keep2.front());
								keep2.pop();
							}
							break;
						}
						else {
							while (!keep2.empty()) {
								route.push(keep2.front());
								keep2.pop();
							}
						}
					}
				}
				ndst = route.front().first;
				count = route.front().second;
				route.pop();
				route.push(make_pair(ndst, count));
			}
			cout << ndst << endl;
			count--;
		}
		cin >> s >> Nachieve;
		for (int j = 0; j < Nachieve; j++)
			cin >> trush;
	}
}


Measured memory_bytes: 1364