#include <iostream>
#include <vector>
#include <utility>
#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;
}

int main() {
		
	// recieve |V| and |E|
	int V, E; std::cin >> V >> E;
	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;
				}
			}
		}
	}

	std::cerr << msec() << std::endl;

	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 deliveredCount = 0;
	const int wantGoStoreRating = 100;

	// recieve info
	for(int t = 0; t < Tmax; t++) {
		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]++;
		}
		// 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 < ORDER.size(); j++){
					if(orderFlag[j] == 1 && nowNode == ORDER[j].second){
						score += Tmax * Tmax - (t - ORDER[j].first) * (t - ORDER[j].first);
						deliveredCount++;
						orderFlag[j] = 2;
						loadedBaggageSum--;
						loadedBaggageCount[ORDER[j].second]--;
					}
				}
			}
			int mintarget = -1;
			int mincost = 999999999;
			if(loadedBaggageSum > 0){
				int cost1 = 0;
				int cost2 = 0;
				int ct1 = 0;
				int ct2 = 0;
				for(int j = 0; j < V; j++){
					if(loadedBaggageCount[j] > 0){
						cost1 += D[nowNode][j];
						ct1 += loadedBaggageCount[j];
					}
					if(unloadedBaggageCount[j] + loadedBaggageCount[j] > 0){
						cost2 += D[nowNode][0]+D[0][j];
						ct2 += unloadedBaggageCount[j] + loadedBaggageCount[j];
					}
				}
				if(cost2 * ct1 < cost1 * ct2 * 3 / 4){
					mintarget = 0;
					mincost = 0;
				}
			}
			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 == -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;
		//if(t % 1000 == 999){
		//	std::cerr << msec() << " " << ORDER.size() << " " << unloadedBaggageSum << "-" << loadedBbaggageSum << "-" << deliveredCount << " " << D[nowNode][0] << std::endl;
		//}
	}
	std::cerr << msec() << " " << score << " " << deliveredCount << std::endl;
	std::cerr << score * 30 << std::endl;
	return 0;
}


Measured memory_bytes: 1152