#include <bits/stdc++.h>
using namespace std;

static const int INFTY = 1e+9;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int VERTEX_MAX = 801;
static const int MAX_ORDER = 10001;

int cost_matrix[VERTEX_MAX][VERTEX_MAX];
int V, E, u, v, cost, Tmax, Nnew, new_id, dst;
int d[VERTEX_MAX], via[VERTEX_MAX];
int output_count = 0;

struct shop
{
	int shop_position = 1;
	deque<tuple<int, int, int>> order;
} Shop;

void dijkstra(int start, int end)
{
	int minv;
	int color[VERTEX_MAX];
	
	for (int i = 0; i < V+1; ++i)
	{
		d[i] = INFTY;
		color[i] = WHITE;
		via[i] = -1;
	}
	
	d[start] = 0;
	color[start] = GRAY;
	
	while(1)
	{
		minv = INFTY;
		int u = -1;
		
		for (int i = 0; i < V+1; ++i)
		{
			if (color[i] != BLACK && d[i] < minv)
			{
				u = i;
				minv = d[i];
			}
		}
		
		if (u == end)
		{
			break;
		}
		
		color[u] = BLACK;
		
		for (int v = 0; v < V+1; ++v)
		{
			if (color[v] != BLACK && cost_matrix[u][v] != INFTY)
			{
				if (d[v] > d[u] + cost_matrix[u][v])
				{
					d[v] = d[u] + cost_matrix[u][v];
					color[v] = GRAY;
					via[v] = u;
				}
			}
		}
	}
}

void delivery(int start, int end)
{
	dijkstra(start, end);
	
	vector<int> start_to_end;
	int node = end;
	start_to_end.push_back(node);
	
	while(1)
	{
		if (start == end)
		{
			break;
		}
		
		node = via[node];
		start_to_end.push_back(node);
		
		if (node == start)
		{
			break;
		}
	}
	
	reverse(start_to_end.begin(), start_to_end.end());
	
	int next_cost[VERTEX_MAX];
	for (int i = 1; i < start_to_end.size(); ++i)
	{
		next_cost[i] = d[start_to_end[i]] - d[start_to_end[i-1]];
		
		for (int j = 0; j < next_cost[i]; ++j)
		{
			if (output_count >= Tmax)
			{
				break;
			}
			cout << start_to_end[i] << endl;
			output_count++;
		}
	}
}

int main() 
{
	cin >> V >> E;
	
	for (int i = 0; i < E; ++i)
	{
		for (int j = 0; j < E; ++j)
		{
			cost_matrix[i][j] = INFTY;
		}
	}
	
	for(int i = 0; i < E; i++)
	{
		cin >> u >> v >> cost;
		
		cost_matrix[u][v] = cost;
		cost_matrix[v][u] = cost;
	}
	
	cin >> Tmax;
	
	for(int i = 0; i < Tmax; i++)
	{
		cin >> Nnew;
		
		for(int j = 0; j < Nnew; j++)
		{
			cin >> new_id >> dst;
			
			Shop.order.emplace_back(i, new_id, dst);
		}
	}
	
	for (int t = 0; t < get<0>(Shop.order[0]); ++t)
	{
		cout << "-1" << endl;
		output_count++;
	}
	
	int order_update = 0;
	int start = Shop.shop_position;
	int end;
	
	for (int t = get<0>(Shop.order[0]); t < Tmax; ++t)
	{
		end = get<2>(Shop.order[order_update]);
		
		delivery(start, end);
		
		delivery(end, start);
		
		if (output_count >= Tmax)
		{
			break;
		}
		
		order_update++;
	}
	
	return 0;
}