#include <iostream>
#include <vector>
#include <utility>
#include <string>

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});
	}

	// calc cost
	std::vector<std::vector<int>> D(V,std::vector<int>(V));
	for(int i = 0; i < V; i++){
		for(int j = 0; j < V; j++){
			D[i][j] = 999999999;
		}
		std::vector<bool> flag(V);
		D[i][i] = 0;
		for(int j = 0; j < V; j++){
			int minnode = -1;
			int mincost = 999999999;
			for(int k = 0; k < V; k++){
				if(flag[k]==false && D[i][k] < mincost){
					minnode = k;
					mincost = D[i][k];
				}
			}
			flag[minnode] = true;
			for(int k = 0; k < G[minnode].size(); k++){
				if(D[i][minnode]+G[minnode][k].second < D[i][G[minnode][k].first]){
					D[i][G[minnode][k].first] = D[i][minnode]+G[minnode][k].second;
				}
			}
		}
	}
	
	// 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);
	const int wantGoStoreRating = 100;

	std::vector<int> patrolRoute;
	int patrolStep = 0;

	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]++;
					}
				}
				patrolRoute.clear();
				patrolStep = 0;
				long long patrolMaxScore = 0;
				for(int r = 0; r < 10; r++){
					std::vector<int> tmpPatrolRoute;
					std::vector<bool> patrolFlag(V);
					int p = nowNode;
					while(true){
						int minNode = -1;
						int minCost = 999999999;
						for(int j = 0; j < V; j++){
							if(patrolFlag[j] == false && loadedBaggageCount[j] > 0){
								int cost = D[p][j] / (r+loadedBaggageCount[j]);
								if(cost < minCost){
									minNode = j;
									minCost = cost;
									for(int k = 0; k < V; k++){
										if(patrolFlag[k] == false && loadedBaggageCount[k] > 0 && D[p][k]+D[k][j]==D[p][j]){
											minNode = k;
										}
									}
								}
							}
						}
						if(minNode == -1){
							break;
						} else {
							tmpPatrolRoute.push_back(minNode);
							patrolFlag[minNode] = true;
							p = minNode;
						}
					}
					long long patrolScore = 0;
					int tmpTime = t;
					int tmpNode = nowNode;
					for(int j = 0; j < tmpPatrolRoute.size(); j++){
						tmpTime += D[tmpNode][tmpPatrolRoute[j]];
						tmpNode = tmpPatrolRoute[j];
						for(int k = 0; k < nodeToOrder[tmpNode].size(); k++){
							int id =  nodeToOrder[tmpNode][k];
							if(orderFlag[id] == 1){
								patrolScore += Tmax * Tmax - (tmpTime - ORDER[id].first) * (tmpTime - ORDER[id].first);
							}
						}
					}
					if(patrolScore > patrolMaxScore){
						patrolRoute = tmpPatrolRoute;
						patrolMaxScore = patrolScore;
					}
				}
			} else {
				if(nowNode == patrolRoute[patrolStep]){
					patrolStep++;
				}
				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]--;
					}
				}
			}
			int mintarget = -1;
			int mincost = 999999999;
			for(int j = 1; j < V; j++){
				if(unloadedBaggageCount[j] > 0){
					int cost = (D[nowNode][0]+D[0][j]) * 10000 / (10000 + unloadedBaggageSum * wantGoStoreRating) / (unloadedBaggageCount[j] + loadedBaggageCount[j]);
					if(cost <= mincost){
						mintarget = 0;
						mincost = cost;
					}
				}
				if(loadedBaggageCount[j] > 0){
					int cost = D[nowNode][j] / loadedBaggageCount[j];
					if(cost < mincost){
						mintarget = j;
						mincost = cost;
					}
				}
			}
			if(mintarget > 0 && patrolStep < patrolRoute.size()){
				//std::cerr << t << " " << mintarget << " " << patrolStep << " " << patrolRoute[patrolStep] << std::endl;
				mintarget = patrolRoute[patrolStep];
			} else if(mintarget == 0){
				patrolRoute.clear();
			}
			if(mintarget == -1 && nowNode > 0){
				mintarget = 0;
			}
			int minNextCost = 999999999;
			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 << score << std::endl;
	return 0;
}


Measured memory_bytes: 2000