#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<endl
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 512;
vi P[N][N];
vi U[N][N];
db E[N][N];
int OR[N * N];
vi comb(vi a,vi b) {
	vi c;
	for (auto it : a)
		c.pb(it);
	for (auto it : b)
		c.pb(it);
	return c;
}

db f(ll a,ll b) {
	return 1.0 * a / b;
}
vi O[N];
int fr[N];
vi G[N];
int cnt[N];
int Fr[N];
const db oo = 1e9;
db D[N];
vi TR[N];
int n,m;
#define ws suka_blea
int ws[N];
void DFS(int bg,int node,int prev,int a,int b) {
	ws[node] = 1;
	if (prev != -1) {
		Fr[node] = prev;
		if (D[node] < 1.0 * a / b) {
			D[node] = 1.0 * a / b;
			int cur = node;
			TR[node].clear();
			while (cur != bg) {
				for (int cs = 0;cs < E[cur][Fr[cur]];++cs)
					TR[node].pb(cur);
				cur = Fr[cur];
			}
			reverse(all(TR[node]));
		}
	} 
	for (auto it : G[node])
		if (it != prev && !ws[it]) {
			DFS(bg,it,node,a + cnt[it],b + E[node][it]);
		}
}
void BFS(int fr) {
	queue < int > Q;
	Q.push(fr);
	for (int i = 1;i <= n;++i)
		D[i] = -oo,TR[i].clear();
	for (int cs = 0;cs < 2000;++cs) {
		for (int i = 1;i <= n;++i)
			random_shuffle(all(G[i])),ws[i] = 0,Fr[i] = -1;
		DFS(fr,fr,-1,0,0);
	}
//	dbg(vi(cnt + 1,cnt + 1 + n));
//	dbg(vector < db > (D + 1,D + 1 + n));
}
int main(void) {
	cin>>n>>m;
	while (m --) {
		int u,v,w;
		cin>>u>>v>>w;
		G[u].pb(v);
		G[v].pb(u);
		E[u][v] = E[v][u] = w;
		for (int i = 0;i < w;++i) {
			P[u][v].pb(v);
			P[v][u].pb(u);
		}
	}
	auto Last = chrono::steady_clock::now().time_since_epoch().count();
	srand(Last);
	for (int k = 1;k <= n;++k)
		for (int i = 1;i <= n;++i)
			for (int j = 1;j <= n;++j)
				if (!P[i][k].empty() && !P[k][j].empty() && ((i != j && P[i][j].empty()) || P[i][j].size() > P[i][k].size() + P[k][j].size()))
					P[i][j] = comb(P[i][k],P[k][j]);
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= n;++j) {
			U[i][j] = P[i][j];
			sort(all(U[i][j]));
			U[i][j].resize(unique(all(U[i][j])) - U[i][j].begin());
		}
	for (int i = 1;i <= n;++i)
		cin>>fr[i];
	cerr << "Pre-Process Time Taken: " << 1.0 * (chrono::steady_clock::now().time_since_epoch().count() - Last) / CLOCKS_PER_SEC << '\n';
	int Tmax;
	cin>>Tmax;
//	dbg(Tmax);
	int last = 0;
	int Vertex = 1;
	vi SHOP;
	auto upd = [&](int i) {
		int Nnew;
		cin>>Nnew;
		while (Nnew --) {
			int ID,v;
			cin>>ID>>v;
			O[v].pb(i);
			OR[ID] = v;
			SHOP.pb(v);
		}
//		dbg(SHOP.size());
		if (Vertex == 1) {
			last = i;
			for (auto it : SHOP) {
				cnt[it] += 1;
			}
			SHOP.clear();
		}
		int Nput;
		cin>>Nput;
//		dbg(Nput);
		while (Nput --) {
			int v;
			cin>>v;
//			dbg(v);
		}
	};
	auto mv = [&](int V) {
		cout << V << '\n';
		fflush(stdout);
		string Verdict;
		fflush(stdin);
		cin>>Verdict;
	//	dbg(Verdict);
		int Nachieve;
		cin>>Nachieve;
//		dbg(Nachieve);
		while (Nachieve --) {
			int v;
			cin>>v;
			cnt[OR[v]] -= 1;
		}
	};
	vi Pth;
	for (int i = 0;i < Tmax;) {
//		dbg(i);
//		dbg(Vertex);
//		dbg(Pth);
		upd(i);
//		dbg(Pth);
//B		dbg(Vertex);
		if (Pth.empty()) {
//			cerr << "passed\n";
			BFS(Vertex);
			int cur;
			if (Vertex != 1) {
				cur = 1;
//				dbg(cur);
			} else {
				cur = max_element(D + 1,D + 1 + n) - D;
			}
			Pth = TR[cur];
			if (abs(D[cur]) < 1e-6 && Vertex == 1) {
				Pth.clear();
			}
//			dbg(Pth.size());
//			dbg(Pth);
//			dbg(Vertex);
//			dbg(vector < db >(cnt + 1,cnt + 1 + n));
		}
		if (!Pth.empty()) {
			mv(Pth[0]);
			if (Pth.size() == 1 || Pth[0] != Pth[1])
				Vertex = Pth[0];
			Pth.erase(Pth.begin());
			++i;
		} else {
			mv(-1);
			++i;
		}
	}
	cerr << "Total Time: " <<  1.0 * (chrono::steady_clock::now().time_since_epoch().count() - Last) / CLOCKS_PER_SEC << '\n';
    return 0;
}

Measured memory_bytes: 110420