#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];
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];
int main(void) {
	int n,m;
	cin>>n>>m;
	while (m --) {
		int u,v,w;
		cin>>u>>v>>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();
	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;
	auto upd = [&](int i) {
		fflush(stdin);
		int Nnew;
		cin>>Nnew;
	//	dbg(Nnew);
		while (Nnew --) {
			int ID,v;
			cin>>ID>>v;
			O[v].pb(i);
		}
		if (Vertex == 1) {
			last = i;
		}
		int Nput;
		cin>>Nput;
	//	dbg(Nput);
		while (Nput --) {
			int v;
			cin>>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;	
		}
	};
	vi Pth;
	for (int i = 0;i < Tmax;) {
	//	dbg(i);
		upd(i);
		if (Pth.empty()) {
			pair < db , int > w = mp(0,1);
			for (int j = 1;j <= n;++j) {
				int cnt1 = lower_bound(all(O[j]),last + 1) - O[j].begin();
	//			dbg(cnt1);
	//			dbg(P[Vertex][j]);
				if (P[Vertex][j].empty())
					continue;
				smax(w,mp(f(cnt1,P[Vertex][j].size()),j));
				int cnt2 = lower_bound(all(O[j]),i + 1 + P[Vertex][1].size()) - O[j].begin();
	//			dbg(cnt2);
				smax(w,mp(f(cnt2,P[Vertex][1].size() + P[1][j].size()),-j));
			}
	//		dbg(w);
			if (!w.fi) {
				mv(-1);
				++i;
				continue;
			}
			if (w.se < 0) {
				Pth = comb(P[Vertex][1],P[1][-w.se]);
			} else {
				Pth = P[Vertex][w.se];
			}
		}
		if (!Pth.empty()) {
			mv(Pth[0]);
			if (Pth.size() == 1 || Pth[0] != Pth[1])
				Vertex = Pth[0];
			Pth.erase(Pth.begin());
			++i;
		}
	}
    return 0;
}

Measured memory_bytes: 88528