#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cassert>
#include <string>
using namespace std;

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

int n, m;
vector< vector< Edge > > edge;
vector< int > freq;
int T_MAX;
// ^----- 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----------------------------------- Solver -----------------------------------v

void COMMAND_STAY() { cout << -1 << endl; }
void COMMAND_MOVE(int w) { cout << w+1 << endl; }

void beforeInput(int t, vector< int >& order_time, vector< int >& order_v, vector< vector< int > >& order_que) {
	int Nt;
	cin >> Nt;
	for (int i=0; i<Nt; ++i) {
		int id, v;
		cin >> id >> v;
		--v;
		order_time[id] = t;
		order_v[id] = v;
	}
	
	int Np;
	cin >> Np;
	for (int i=0; i<Np; ++i) {
		int id;
		cin >> id;
		order_que[order_v[id]].push_back(order_time[id]);
	}	
}

void afterInput() {
	string verdict;
	cin >> verdict;
	if (verdict == "NG") exit(0);
	
	int Na;
	cin >> Na;
	for (int i=0; i<Na; ++i) {
		int id;
		cin >> id;
	}
}

void solve() {
	vector< int > order_time(T_MAX, -1);
	vector< int > order_v(T_MAX, -1);
	vector< vector< int > > order_que(n, vector< int >());
	
	int cur_v = 0, tar_v = -1, len = 0;
	for (int t=0; t<T_MAX; ++t) {
		// before input
		beforeInput(t, order_time, order_v, order_que);
		
		// decide target
		if (tar_v == -1 || len == 0) {
			tar_v = 0;
			int min_value = 1L << 30;
			for (int v=1; v<n; ++v) {
				int value = getDist(cur_v, v);
				if (!order_que[v].empty() && min_value > value) {
					tar_v = v;
					min_value = value;
				}
			}
		}
		
		if (cur_v == tar_v) {
			COMMAND_STAY();
			tar_v = -1;
		}
		else {
			int nxt_v = getNext(cur_v, tar_v);
			if (len == 0) len = getLen(cur_v, nxt_v);
			COMMAND_MOVE(nxt_v);
			--len;
			if (len == 0) cur_v = nxt_v;
			if (cur_v == tar_v) {
				order_que[tar_v].clear();
				tar_v = -1;
			}
		}
		
		// after input
		afterInput();
	}
}

// ^----------------------------------- 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();
	
	freq.assign(n, -1);
	for (int i=0; i<n; ++i) cin >> freq[i];
	cin >> T_MAX;
	
	solve();
}

Measured memory_bytes: 3284