#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>
#include <time.h>

#define Inf 2000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(X) (X).begin(),(X).end()
#define graph_from1 true
#define graph_tree false
#define graph_weight true
#define graph_digraph false
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int debug = 0; // 0 : 提出, 1 : コードテスト, 2 : fin - fout
double time_ratio;
clock_t time_ini;

int V, E;
vector<vector<Pii>> G(V);

typedef struct {
	int new_id;
	int time;
	int dst;
}Order;

typedef struct {
	int Nnew;
	vector<Order> orders;
}Info;

class Info_all{
public:
	int Tmax;
	vector<Info> infos;
	vector<Order> idlist;
};

class Command_all {
public:
	int Tmax;
	vi commands;
};

class Graph_func
{
public:
	int Vnum;
	int Enum;
	vector<pair<int, int> > edgelist;
	vector<int> edgeweight;
	vector<vector<int> > adjlist;
	vector<vector<int> > adjlistweight;
	vector<int> adjnum;

	vector<int> xdist;
	vector<vi> xydist;
	vector<vi> xylen;
	vi x_from;
	vector<vi> xy_from;

	vector<bool> x_visited;
	vector<int> x_prqarr;
	vector<bool> x_filled;

	void graphini();
	void adjini();
	void visited_ini();
	void adjsort();
	void graph_BFS(int BFS_ini);
	void graph_DFS(int DFS_ini);
	void xyDist(int x);   // ex. xyDist(3, 0)
	int dim_num(int dim);

	bool xydist_def = false;
};

void Graph_func::graphini()
{
	edgelist.resize(Enum);
	edgeweight.resize(Enum);
	adjnum.resize(Vnum);
	xdist.resize(Vnum);
	adjlist.resize(Vnum);
	adjlistweight.resize(Vnum);
	xydist.resize(Vnum);
	xylen.resize(Vnum);
	x_from.resize(Vnum);
	xy_from.resize(Vnum);
	rep(i, Vnum) {
		xydist[i].resize(Vnum);
		xylen[i].resize(Vnum);
		xy_from[i].resize(Vnum);
		rep(j, Vnum) {
			xylen[i][j] = -1;
		}
	}
	return;
}

void Graph_func::adjini()
{
	for (int i = 0; i < Vnum; i++)
		adjnum[i] = 0;
	for (int i = 0; i < Enum; i++)
	{
		int x = edgelist[i].first;
		int y = edgelist[i].second;
		adjlist[x].push_back(y);
		adjlist[y].push_back(x);
		int xyweight = edgeweight[i];
		adjlistweight[x].push_back(xyweight);
		adjlistweight[y].push_back(xyweight);
		xylen[x][y] = xyweight;
		xylen[y][x] = xyweight;
		adjnum[x]++;
		adjnum[y]++;
	}
	x_visited.resize(Vnum);
	visited_ini();

	return;
}

void Graph_func::visited_ini()
{
	for (int i = 0; i < Vnum; i++)
		x_visited[i] = false;
	x_prqarr.resize(0);
}

void Graph_func::adjsort()
{
	for (int i = 0; i < Vnum; i++)
		sort(adjlist[i].begin(), adjlist[i].end(), less<int>());
	return;
}



void Graph_func::graph_BFS(int BFS_ini)
{
	visited_ini();
	x_prqarr.push_back(BFS_ini);
	x_visited[BFS_ini] = true;

	while (!x_prqarr.empty())
	{
		int Ntmp = x_prqarr.size();
		for (int a = 0; a < Ntmp; a++)
		{
			int x = x_prqarr[0];
			x_prqarr.erase(x_prqarr.begin());
			for (int i = 0; i < adjnum[x]; i++)
			{
				int x_new = adjlist[x][i];
				if (!x_visited[x_new])
				{
					x_prqarr.push_back(x_new);
					x_visited[x_new] = true;
				}
			}
		}
	}
	return;
}

void Graph_func::graph_DFS(int DFS_ini)
{
	visited_ini();
	x_prqarr.push_back(DFS_ini);
	x_visited[DFS_ini] = true;

	while (!x_prqarr.empty())
	{
		int Ntmp = x_prqarr.size();
		for (int a = 0; a < Ntmp; a++)
		{
			int x = x_prqarr[x_prqarr.size() - 1];
			x_prqarr.pop_back();
			for (int i = 0; i < adjnum[x]; i++)
			{
				int x_new = adjlist[x][i];
				if (!x_visited[x_new])
				{
					x_prqarr.push_back(x_new);
					x_visited[x_new] = true;
				}
			}
		}
	}
	return;
}

void Graph_func::xyDist(int x)  // ex. xyDist(3), Dijkstra's algorithm
{
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > xdist_que; //Alive_vertices
	for (int i = 0; i < Vnum; i++)
		xdist[i] = Inf;
	xdist[x] = 0;
	x_from[x] = x;
	pair<int, int> xdist_que_tmp;
	xdist_que_tmp.first = 0;
	xdist_que_tmp.second = x;
	xdist_que.push(xdist_que_tmp);
	while (!xdist_que.empty())
	{
		xdist_que_tmp = xdist_que.top();
		xdist_que.pop();
		int xdist_tmp = xdist_que_tmp.first;
		int x_tmp = xdist_que_tmp.second;
		if (xdist[x_tmp] == xdist_tmp)
		{
			for (int i = 0; i < adjnum[x_tmp]; i++)
			{
				int x_new = adjlist[x_tmp][i];
				int dist_diff;
				if (graph_weight)
					dist_diff = adjlistweight[x_tmp][i];
				else dist_diff = 1;
				if (xdist[x_new] > xdist[x_tmp] + dist_diff)
				{
					x_from[x_new] = x_tmp;
					xdist[x_new] = xdist[x_tmp] + dist_diff;
					xdist_que_tmp.first = xdist[x_new];
					xdist_que_tmp.second = x_new;
					xdist_que.push(xdist_que_tmp);
				}
			}
		}
	}
	/*rep(i, V) {
		int x_tmp = i;
		while (1) {
			xway[i].push_back(x_tmp);
			if (x_tmp == x)
				break;
			x_tmp = x_from[x_tmp];
		}
		if (i == x)
			xway[i].push_back(x);
		reverse(xway[i].begin(), xway[i].end());
	}*/
}

int Graph_func::dim_num(int dim)
{
	int anstmp = 0;
	for (int i = 0; i < Vnum; i++)
	{
		if (adjnum[i] == dim)
			anstmp++;
	}
	return anstmp;
}

Graph_func graph;
Info_all info_all;
Command_all command_all;
vector<vi> dst_to_id;

void readProblem() {
	string sample;
	ifstream fin;
	if (debug == 2)
		fin.open("input.txt");
	if (debug == 2)
		fin >> V >> E;
	else
		cin >> V >> E;
	graph.Vnum = V;
	graph.Enum = E;

	graph.graphini();

	rep(i, E) {
		// recieve edges
		int u, v, d;
		if (debug == 2)
			fin >> u >> v >> d;
		else
			cin >> u >> v >> d;
		u--; v--;
		graph.edgelist[i].first = u;
		graph.edgelist[i].second = v;
		graph.edgeweight[i] = d;
		//G[u].push_back({ v, d });
		//G[v].push_back({ u, d });
	}

	int Tmax;
	if (debug == 2)
		fin >> Tmax;
	else
		cin >> Tmax;
	info_all.Tmax = Tmax;
	info_all.infos.resize(Tmax);
	dst_to_id.resize(V);


	// recieve info
	rep(t, Tmax) {
		int Nnew;
		if (debug == 2)
			fin >> Nnew;
		else
			cin >> Nnew;
		info_all.infos[t].Nnew = Nnew;
		vector<Order> order;
		for (int n = 0; n < Nnew; n++) {
			Order order_tmp;
			if (debug == 2)
				fin >> order_tmp.new_id >> order_tmp.dst;
			else
				cin >> order_tmp.new_id >> order_tmp.dst;
			order_tmp.new_id--;
			order_tmp.dst--;
			order_tmp.time = t;
			order.push_back(order_tmp);
			info_all.idlist.push_back(order_tmp);
			dst_to_id[order_tmp.dst].push_back(order_tmp.new_id);
		}
		info_all.infos[t].orders = order;
	}

	if (debug == 2)
		fin.close();

	if (debug == 2)
		time_ratio = 0.115;
	else
		time_ratio = 1;

	graph.adjini();

	command_all.Tmax = Tmax;
	command_all.commands.resize(Tmax);

	return;
}

void writeSolution() {
	ofstream fout;
	if (debug == 2)
		fout.open("output.txt");

	rep(i, command_all.Tmax) {
		int command = command_all.commands[i];
		if (command != -1)
			command++;
		if (debug == 2)
		{
			fout << command << endl;
		}
		else {
			cout << command << endl;
		}
	}

	if (debug == 2)
		fout.close();

	return;
}

void write_val(int val_tmp, string S)
{
	if (debug != 0)
		cout << val_tmp << S << endl;
	return;
}

double time_diff()
{
	int time_tmp = clock();
	const double time = time_ratio * static_cast<double>(time_tmp - time_ini) / CLOCKS_PER_SEC * 1000.0;
	return time;
}

int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void solve() {
	rep(i, V) {
		graph.xyDist(i);
		graph.xydist[i] = graph.xdist;
		graph.xy_from[i] = graph.x_from;
	}
	int x_begin = 0;
	int x_end = 0;
	int x_prev = 0;
	int x_next = 0;
	int x_len_from_prev = 0;
	vi x_list(2);
	int x_list_i = 0;
	set<int> waitinglist;
	set<int> loadedlist;
	int dist_max = 0;

	bool x_0 = true; // 店舗にいる
	bool new_dst = false; // 目的地を更新
	rep(t, info_all.Tmax) {
		Info info_tmp = info_all.infos[t];
		rep(n, info_tmp.Nnew) {
			waitinglist.insert(info_tmp.orders[n].new_id);
		}
		int waitingnum = waitinglist.size();
		int loadednum = loadedlist.size();

		// ---------- 店舗にいる場合の処理	 ----------

		if (x_0) {
			if (waitingnum == 0 && loadednum == 0) { // 店舗にいて注文なし
				command_all.commands[t] = -1;
			}
			else { // 店舗にいて注文あり
				//write_val(loadedlist.size(), "A");
				//write_val(waitinglist.size(), "A");
				auto it = waitinglist.begin();
				for (int id_tmp : waitinglist) {
					//write_val(id_tmp, " A");
					loadedlist.insert(id_tmp);
				}
				waitinglist.clear();
				new_dst = true;
			}
		}

		// ---------- 目的地を更新する場合の処理	 ----------

		if (new_dst) {
			new_dst = false;
			float dist_min = Inf; // 行先 : 店舗
			float eval_waiting = waitingnum - 300;
			eval_waiting = max(eval_waiting, (float)0.0);
			eval_waiting /= 1000.0;
			eval_waiting++;
			int x_end_nxt = -1;
			int id_nxt = -1;
			if (!x_0 && (loadednum == 0 || waitingnum != 0)) {
				dist_min = (float)graph.xydist[x_end][0]; // 行先 : 店舗
				x_end_nxt = 0;
			}
			x_0 = false;
			//write_val(loadedlist.size(), "A");
			if (loadedlist.size() != 0) {
				for (int id_tmp : loadedlist) {
					int x = x_end;
					int y = info_all.idlist[id_tmp].dst;
					float t_over = t - info_all.idlist[id_tmp].time;
					t_over /= 100000.0;
					t_over++;
					//int eval = (float)graph.xydist[x][y] / t_over;
					float eval = (float)graph.xydist[x][y];
					if (dist_min > eval) {
						dist_min = eval;
						x_end_nxt = y;
						id_nxt = id_tmp;
					}
				}
			}
			if (id_nxt != -1) {
				auto it = loadedlist.find(id_nxt);
				if (it == loadedlist.end()) {
					cout << "not found" << endl;
					while (1)
						;
				}
				loadedlist.erase(it);
			}
			x_begin = x_end;
			x_end = x_end_nxt;
			int x_tmp = x_end;
			x_list.clear();
			x_list.push_back(-1);
			while (1) {
				x_list.push_back(x_tmp);
				if (x_tmp == x_begin)
					break;
				x_tmp = graph.xy_from[x_begin][x_tmp];
			}
			reverse(x_list.begin(), x_list.end());
			x_prev = x_list[0];
			x_next = x_list[1];
			x_len_from_prev = 0;
			x_list_i = 0;
		}

		// ---------- 配達途中の場合の処理	 ----------

		if (x_end != x_prev) {
			x_len_from_prev++;
			command_all.commands[t] = x_next;
			if (graph.xylen[x_prev][x_next] == x_len_from_prev) { // 次の頂点に移動
				int dstnum = dst_to_id[x_next].size();
				rep(i, dstnum) { // たまたま配達した
					int id_tmp = dst_to_id[x_next][i];
					auto it = loadedlist.find(id_tmp);
					if (it != loadedlist.end()) {
						loadedlist.erase(it);
					}
				}
				x_len_from_prev = 0;
				x_list_i++;
				x_prev = x_list[x_list_i];
				x_next = x_list[x_list_i + 1];
			}
			if (x_end == x_prev) { // 移動完了
				if (x_end == 0) { // 店舗到着
					new_dst = false;
					x_0 = true;
				}
				else { // 配達完了
					new_dst = true;
					x_0 = false;
				}
			}
		}
	}
	write_val(loadedlist.size(), "L");
	write_val(waitinglist.size(), "W");
	return;
}

void sample(int time_ms) {
	const double time = time_diff();
	if (time >= time_ms)
		return;
	int _rand = xor128();

	return;
}

int main() {
	readProblem();
	solve();
	writeSolution();
	return 0;
}


Measured memory_bytes: 2944