#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int dist[400][400];
int nxt_to[400][400];
int edge[400][400];
int freq[400];

int lastTumi = -1;
vector<int> ordered_time[400];
tuple<int, int, int> cur;
set<int> donthave, having;


pair<int, int> dist_to(int u, int v, int d, int dst) { // on edge u-v dist d
	if (d == 0) {
		if (u == dst)return make_pair(0, -2);
		return make_pair(dist[u][dst], nxt_to[u][dst]);
	}
	else if (d + dist[u][dst] < edge[u][v] - d + dist[v][dst]) {
		return make_pair(d + dist[u][dst], u);
	}
	else {
		return make_pair(edge[u][v] - d + dist[v][dst], v);
	}
}

tuple<int, int, int> move(const tuple<int, int, int> & cur, int dst) {
	if (dst == -2)return cur;
	int u, v, d;
	tie(u, v, d) = cur;
	if (u == dst) {
		d--;
		if (d == 0)return make_tuple(u, -1, 0);
		else return make_tuple(u, v, d);
	}
	else if (v == dst) {
		d++;
		if (d == edge[u][v])return make_tuple(v, -1, 0);
		else return make_tuple(u, v, d);
	}
	else {
		//assert(d == 0);
		if (edge[u][dst] > 1)return make_tuple(u, dst, 1);
		else return make_tuple(dst, -1, 0);
	}
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);


	// recieve |V| and |E|
	int V, E; std::cin >> V >> E;
	rep(u, V)rep(v, V)dist[u][v] = INF;
	memset(nxt_to, -1, sizeof(nxt_to));
	memset(edge, -1, sizeof(edge));

	for (int i = 0; i < E; i++) {
		// recieve edges
		int u, v, d; std::cin >> u >> v >> d;
		u--; v--;
		dist[u][v] = dist[v][u] = d;
		edge[u][v] = d;
		edge[v][u] = d;
	}
	rep(i, V)dist[i][i] = 0;
	rep(k, V)rep(i, V)rep(j, V)
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

	rep(i, V) {
		rep(j, V)if (edge[i][j] != -1) {
			rep(k, V) {
				if (edge[i][j] + dist[j][k] == dist[i][k]) {
					nxt_to[i][k] = j;
				}
			}
		}
	}
	rep(i, V)cin >> freq[i];


	int Tmax; std::cin >> Tmax;

	cur = make_tuple(0, -1, 0);
	bool flag = false;


	for (int i = 0; i < Tmax; i++) {
		//std::cout << -1 << std::endl;

		// recieve info
		int Nnew; std::cin >> Nnew;
		for (int j = 0; j < Nnew; j++) {
			int new_id, dst; std::cin >> new_id >> dst;

			ordered_time[dst - 1].push_back(i);
			donthave.insert(dst - 1);
		}
		int Nput; std::cin >> Nput;
		for (int j = 0; j < Nput; j++) {
			int put_id;
			cin >> put_id;
		}

		if (get<2>(cur) == 0 && get<0>(cur) == 0) {
			lastTumi = i;
			having.insert(all(donthave));
			donthave.clear();
			flag = false;
		}

		if (having.size()) {
			int u, v, d;
			tie(u, v, d) = cur;
			auto mi = make_pair(INF, -1);
			for (int dst : having) {
				mi = min(mi, dist_to(u, v, d, dst));
			}
			if (flag) mi = min(mi, dist_to(u, v, d, 0));

			cout << mi.second + 1 << endl;
			cur = move(cur, mi.second);
		}
		else {
			int u, v, d;
			tie(u, v, d) = cur;
			auto p = dist_to(u, v, d, 0);

			cout << p.second + 1 << endl;
			cur = move(cur, p.second);
		}

		if (get<2>(cur) == 0) {
			int u = get<0>(cur);
			while (ordered_time[u].size() && ordered_time[u].front() <= lastTumi) {
				ordered_time[u].erase(ordered_time[u].begin());
				flag = true;
			}
			having.erase(u);
		}


		std::string verdict; std::cin >> verdict;
		if (verdict == "NG") {
			return 1;
		}

		// the number of orders that have been delivered at time t.
		int Nachive; std::cin >> Nachive;
		for (int j = 0; j < Nachive; j++) {
			int achive_id; std::cin >> achive_id;
		}
	}


	return 0;
}

Measured memory_bytes: 3144