#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;
				}
			}
		}
	}
	//for(int i = 0; i < V; i++){
	//	for(int j = 0; j < V; j++){
	//		std::cerr << D[i][j] << " ";
	//	}
	//	std::cerr << std::endl;
	//}
	
	// recieve freqencies
	std::vector<int> freq(V);
	for(int i = 0; i < V; i++) std::cin >> freq[i];
	
	int Tmax; std::cin >> Tmax;

	std::vector<std::pair<int, int>> ORDER;
	
	int nowNode = 0;
	int targetNode = 0;
	int remainDist = 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--;
			ORDER.push_back({0, dst});
		}
	
		// 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;
		}

		int ans = -1;
		if(remainDist == 0){
			nowNode = targetNode;
			int mintarget = -1;
			int mincost = 999999999;
			for(int j = 0; j < ORDER.size(); j++){
				if(ORDER[j].first == 1 && nowNode == ORDER[j].second){
					ORDER[j].first = 2;
				}
				if(nowNode == 0 && ORDER[j].first == 0){
					ORDER[j].first = 1;
				}
				if(ORDER[j].first == 1){
					if(D[nowNode][ORDER[j].second] < mincost){
						mintarget = ORDER[j].second;
						mincost = D[nowNode][ORDER[j].second];
					}
				}
			}
			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--;
        }
		std::cout << ans << std::endl;
		
    // insert your code here to get more meaningful output
		// you have to output a command here
	//	std::cout << -1 << std::endl; // stay

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

	return 0;
}

Measured memory_bytes: 2000