#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <string>
#include <chrono>
 
auto start = std::chrono::system_clock::now();
auto msec() {
	auto end = std::chrono::system_clock::now();
	auto dur = end - start;
	auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
	return ms;
}

typedef std::pair<int, int> P;
 
const int INF = 999999999;

int main() {
		
	// recieve |V| and |E|
	int V, E; std::cin >> V >> E;

	// adjacency list
	std::vector<std::vector<std::pair<int, int>>> G(V);

	for(int i = 0; i < E; i++) {
		// recieve edges
		int u, v, d; std::cin >> u >> v >> d;
		u--; v--;
		G[u].push_back({v, d});
		G[v].push_back({u, d});
	}

	std::vector<std::vector<int>> D(V,std::vector<int>(V,INF));
	std::vector<std::vector<int>> prever(V,std::vector<int>(V,-1));
	for(int i = 0; i < V; i++){
		std::vector<bool> flag(V);
		D[i][i] = 0;
		std::priority_queue<P, std::vector<P>, std::greater<P> > que;
		que.push(P(0,i));
		while(!que.empty()){
			P p = que.top();
			que.pop();
			int v = p.second;
			if(D[i][v] < p.first){
				continue;
			}
			for(int j=0;j<G[v].size();j++){
				int e = G[v][j].first;
				if(D[i][e] > D[i][v] + G[v][j].second){
					D[i][e] = D[i][v] + G[v][j].second;
					prever[i][e] = v;
					que.push(P(D[i][e],e));
				}
			}
		}
	}
	
	// recieve freqencies
	std::vector<int> freq(V);
	for(int i = 0; i < V; i++) std::cin >> freq[i];
	
	int Tmax; std::cin >> Tmax;
	long long score = 0;
	std::vector<int> orderFlag;
	std::vector<std::pair<int, int>> ORDER;
  
	int nowNode = 0;
	int targetNode = 0;
	int remainDist = 0;
	int unloadedBaggageSum = 0;
	std::vector<int> unloadedBaggageCount(V,0);
	int loadedBaggageSum = 0;
	std::vector<int> loadedBaggageCount(V,0);
	int deliveredSum = 0;
	std::vector<int> deliveredCount(V,0);
	std::vector<std::vector<int>> nodeToOrder(V);

	for(int t = 0; t < Tmax; t++) {

		// the number of new order
		int Nnew; std::cin >> Nnew;
		for(int j = 0; j < Nnew; j++) {
			int new_id, dst; std::cin >> new_id >> dst;
			dst--;
			orderFlag.push_back(0);
			ORDER.push_back({t, dst});
			unloadedBaggageSum++;
			unloadedBaggageCount[dst]++;
			nodeToOrder[dst].push_back(orderFlag.size()-1);
		}
	
		// the number of items transfered into the car at time t.
		int Nput; std::cin >> Nput;
		for(int j = 0; j < Nput; j++) {
			int put_id; std::cin >> put_id;
		}

		// insert your code here to get more meaningful output
		int ans = -1;
		if(remainDist == 0){
			nowNode = targetNode;
			if(nowNode == 0){
				for(int j = 0; j < ORDER.size(); j++){
					if(orderFlag[j] == 0){
						orderFlag[j] = 1;
						unloadedBaggageSum--;
						loadedBaggageSum++;
						unloadedBaggageCount[ORDER[j].second]--;
						loadedBaggageCount[ORDER[j].second]++;
					}
				}
			} else {
				for(int j = 0; j < nodeToOrder[nowNode].size(); j++){
					int id = nodeToOrder[nowNode][j];
					if(orderFlag[id] == 1){
						score += Tmax * Tmax - (t - ORDER[id].first) * (t - ORDER[id].first);
						orderFlag[id] = 2;
						deliveredSum++;
						deliveredCount[ORDER[id].second]++;
						loadedBaggageSum--;
						loadedBaggageCount[ORDER[id].second]--;
					}
				}
			}
			std::vector<int> patrolRoute;
			std::vector<bool> patrolFlag(V);
			int patrolTime = t;
			long long patrolScore = 0;
			int patrolNode = nowNode;
			patrolRoute.push_back(nowNode);
			while(true){
				int minCost = INF;
				int minNode = -1;
				for(int j = 0; j < V; j++){
					if(patrolFlag[j] == false && (j == 0 || loadedBaggageCount[j] > 0)){
						int cost = D[patrolNode][j];
						if(cost < minCost){
							minCost = cost;
							minNode = j;
						}
					}
				}
				if(minNode == -1){
					//patrolTime += D[patrolNode][0];
					//patrolRoute.push_back(0);
					break;
				}
				for(int j = 0; j < nodeToOrder[minNode].size(); j++){
					int id = nodeToOrder[minNode][j];
					if(orderFlag[id] == 1){
						patrolScore += Tmax * Tmax - (patrolTime - ORDER[id].first) * (patrolTime - ORDER[id].first);
					}
				}
				patrolTime += minCost;
				patrolRoute.push_back(minNode);
				patrolNode = minNode;
				patrolFlag[minNode] = true;
			}
			int patrolLength = patrolRoute.size();
			bool changeFlag = false;
			if(patrolLength >= 3){
				for(int r = 0; r < 1000; r++){
					int rnd1 = r*10007%(patrolLength-2)+1;
					int rnd2 = r*99991%(patrolLength-2)+1;
 					if(rnd2 <= rnd1){
						continue;
					}
					int node1 = patrolRoute[rnd1-1];
					int node2 = patrolRoute[rnd1];
					int node3 = patrolRoute[rnd2];
					int node4 = patrolRoute[rnd2+1];
					int beforeCost = D[node1][node2] + D[node3][node4];
 					int afterCost = D[node1][node3] + D[node2][node4];
					if(afterCost <= beforeCost + (1000-r)/100){
						std::vector<int> tmpRoute;
						for(int i = 0; i < rnd1; i++){
							tmpRoute.push_back(patrolRoute[i]);
						}
						for(int i = rnd2; i >= rnd1; i--){
							tmpRoute.push_back(patrolRoute[i]);
						}
						for(int i = rnd2+1; i < patrolLength; i++){
							tmpRoute.push_back(patrolRoute[i]);
						}
						long long tmpScore = 0;
						int tmpTime = t;
						for(int i = 1; i < patrolLength; i++){
							int node = tmpRoute[i];
							tmpTime += D[tmpRoute[i-1]][tmpRoute[i]];
							for(int j = 0; j < nodeToOrder[node].size(); j++){
								int id = nodeToOrder[node][j];
								if(orderFlag[id] == 1){
									tmpScore += Tmax * Tmax - (tmpTime - ORDER[id].first) * (tmpTime - ORDER[id].first);
								}
							}
						}
						if(tmpScore >= patrolScore){
							patrolRoute = tmpRoute;
							changeFlag = true;
							patrolScore = tmpScore;
						}
					}
				}
			}
			if(!changeFlag){
				patrolRoute.clear();
			}
			int mintarget = -1;
			int mincost = INF;
			for(int j = 1; j < V; j++){
				if(unloadedBaggageCount[j] > 0){
					int cost = 10 * (D[nowNode][0]+D[0][j]) * 100 / (100 + unloadedBaggageSum) / (unloadedBaggageCount[j] + loadedBaggageCount[j]);
					if(cost <= mincost){
						mintarget = 0;
						mincost = cost;
					}
				}
				if(loadedBaggageCount[j] > 0){
					int cost = 10 * D[nowNode][j] * (1 + unloadedBaggageCount[j]) / 1 / loadedBaggageCount[j];
					if(cost < mincost){
						mintarget = j;
						mincost = cost;
					}
				}
			}
			if(mintarget > 0 && patrolRoute.size() > 1){
				mintarget = patrolRoute[1];
			}
			if(mintarget == -1 && nowNode > 0){
				mintarget = 0;
			}
			int minNextCost = INF;
			if(mintarget >= 0){
				for(int j = 0; j < G[nowNode].size(); j++){
					if(D[G[nowNode][j].first][mintarget] < minNextCost){
						ans = G[nowNode][j].first + 1;
						targetNode = ans - 1;
						remainDist = G[nowNode][j].second - 1;
						minNextCost = D[G[nowNode][j].first][mintarget];
					}
				}
			}
		} else {
			ans = targetNode + 1;
			remainDist--;
		}
		// you have to output a command here
		std::cout << ans << std::endl;

		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;
		}
		
	}
	std::cerr << msec() << " " << score << " " << deliveredSum << std::endl;
	std::cerr << score * 30 << std::endl;
	return 0;
}


Measured memory_bytes: 2640