#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> PP;

const int mod = 1000000007;
const int INF = 1000000100;

struct edge { int to, length, type, num; };

// �����l�̕ϐ�
int V, E;
int u[2000], v[2000], d[2000], e[2000][2];
int f[700];
int t[5][5];
int P_light, T_warning, T_max;

// �et�ɂ�����ϐ�
string car_status;
int warning_time;
int jam[5];
int N_cancel;
vector<int> cancel_id;
int N_new, new_id, dst;
int N_put;
vector<int> put_id;

string vertict;
int waiting_time;
int N_achieve;
vector<int> achieve_id;

// ���̑�
vector<edge> road[700]; // i����̓��H(��ʓ��̋�����4�{)
int dist[700][700];
int num_road, location, num_point; // ���H�̔ԍ���u����̋����ƌ��݈ʒu�i�_�j
int root[700][700];
int op;
int task[100010];
map<int, int> new_order;
map<int, int> put_order;
int destination;

void init()
{
	cin >> V >> E;
	for (int i = 1; i <= E; i++)
	{
		cin >> u[i] >> v[i] >> d[i];/* >> e[i][0] >> e[i][1];*/
		road[u[i]].push_back(edge{ v[i], d[i], e[i][0], i });
		road[v[i]].push_back(edge{ u[i], d[i], e[i][1], i });
	}
	for (int i = 1; i <= V; i++)
	{
		cin >> f[i];
	}
	/*for (int i = 1; i <= 4; i++)
	{
		for (int j = 1; j <= 4; j++)
		{
			cin >> t[i][j];
		}
	}*/
	//cin >> P_light >> T_warning >> T_max;
	cin >> T_max;
	num_point = 1, num_road = 0;
}

void input_first()
{
	/*cin >> car_status;
	if (car_status == "WARNING")
	{
		cin >> warning_time;
	}
	for (int i = 1; i <= 4; i++)
	{
		cin >> jam[i];
	}
	cin >> N_cancel;
	cancel_id.push_back(0);
	for (int i = 1; i <= N_cancel; i++)
	{
		int id;
		cin >> id;
		cancel_id.push_back(id);
	}*/
	cin >> N_new;
	for (int i = 1; i <= N_new; i++)
	{
		cin >> new_id >> dst;
	}
	cin >> N_put;
	put_id.push_back(0);
	for (int i = 1; i <= N_put; i++)
	{
		int id;
		cin >> id;
		put_id.push_back(id);
	}
}

void output()
{
	if (op == 0) op = -1;
	cout << op << endl;
}

void reflesh()
{
	cancel_id.clear();
	put_id.clear();
	achieve_id.clear();
}

void input_last()
{
	cin >> vertict;
	if (vertict == "NG")
	{
		return;
	}
	if (vertict == "WAIT")
	{
		cin >> waiting_time;
	}
	cin >> N_achieve;
	achieve_id.push_back(0);
	for (int i = 1; i <= N_achieve; i++)
	{
		int id;
		cin >> id;
		achieve_id.push_back(id);
	}
}

void dijkstra(int s)
{
	for (int i = 1; i <= V; i++)
	{
		dist[s][i] = INF;
	}

	priority_queue<PP, vector<PP>, greater<PP>> que;
	que.push(PP(P(0, s), 0));

	while (que.size())
	{
		PP pp = que.top(); que.pop();
		int v = pp.first.second, d = pp.first.first, rt = pp.second;

		if (dist[s][v] != INF) continue;
		dist[s][v] = d, root[s][v] = rt;

		for (int i = 0; i < road[v].size(); i++)
		{
			if (dist[s][road[v][i].to] != INF) continue;
			que.push(PP(P(d + road[v][i].length, road[v][i].to), v));
		}
	}
}

void move()
{
	if (op == -1)
	{
		return;
	}
	else if (num_road == 0)
	{
		for (int i = 0; i < road[num_point].size(); i++)
		{
			if (road[num_point][i].to == op)
			{
				num_road = road[num_point][i].num;

				if (d[num_road] == 1)
				{
					num_road = 0;
					num_point = op;
				}
				else if (num_point == u[num_road])
				{
					location = 1;
				}
				else
				{
					location = d[num_road] - 1;
				}
				break;
			}
		}
	}
	else if (u[num_road] == op)
	{
		location--;
		if (location == 0)
		{
			num_point = op;
			num_road = 0;
		}
	}
	else
	{
		location++;
		if (location == d[num_road])
		{
			num_point = op;
			num_road = 0;
		}
	}

}

void return_to_store()
{
	if (num_road == 0)
	{
		if (num_point == 1)
		{
			op = -1;
		}
		else
		{
			op = root[1][num_point];
		}
	}
	else
	{
		int via_u = dist[1][u[num_road]], via_v = dist[1][v[num_road]];
		via_u += location, via_v += d[num_road] - location;
		if (via_u < via_v)
		{
			op = u[num_road];
		}
		else
		{
			op = v[num_road];
		}
	}
}

void go_to_destination()
{
	if (num_road == 0)
	{
		op = root[destination][num_point];
		if (op == 0)
		{
			op = -1;
		}
	}
	else
	{
		int via_u = dist[destination][u[num_road]], via_v = dist[destination][v[num_road]];
		via_u += location, via_v += d[num_road] - location;
		if (via_u < via_v)
		{
			op = u[num_road];
		}
		else
		{
			op = v[num_road];
		}
	}
}

void action_selection()
{
	if (N_put > 0)
	{
		int len = INF, des = 0;
		if (destination != 0)
		{
			des = destination;
			len = dist[1][destination];
		}
		for (int i = 1; i <= N_put; i++)
		{
			if (len > dist[1][put_order[put_id[i]]])
			{
				len = dist[1][put_order[put_id[i]]];
				des = put_order[put_id[i]];
			}
		}
		destination = des;
	}

	if (vertict == "WAIT")
	{
		op = -1;
	}
	else
	{
		if (put_order.size() < new_order.size() || (new_order.size() == 0 && put_order.size() == 0) || destination == 0)
		{
			return_to_store();
		}
		else
		{
			go_to_destination();
		}
	}
	/*else if (car_status == "WARNING")
	{
		return_to_store();
	}
	else if (car_status == "NOT_BROKEN")
	{
		if (put_order.size() < new_order.size() || (new_order.size() == 0 && put_order.size() == 0) || destination == 0)
		{
			return_to_store();
		}
		else
		{
			go_to_destination();
		}
	}
	else
	{
		op = -1;
	}*/
}

void order_status()
{
	for (int i = 1; i <= N_cancel; i++)
	{
		new_order[cancel_id[i]] = 0;
		put_order[cancel_id[i]] = 0;
		new_order.erase(cancel_id[i]);
		put_order.erase(cancel_id[i]);
	}

	if (N_new == 1)
	{
		new_order[new_id] = dst;
	}

	for (int i = 1; i <= N_put; i++)
	{
		put_order[put_id[i]] = new_order[put_id[i]];
		new_order[put_id[i]] = 0;
		new_order.erase(put_id[i]);
	}
}

void sale()
{
	for (int i = 1; i <= N_achieve; i++)
	{
		put_order.erase(achieve_id[i]);
	}
	int len = INF, des = 0;

	for (auto itr = put_order.begin(); itr != put_order.end(); ++itr)
	{
		if (len > dist[num_point][itr->second])
		{
			len = dist[num_point][itr->second];
			des = itr->second;
		}
	}

	destination = des;
}

int main(void)
{
	init();

	for (int i = 1; i <= V; i++)
	{
		dijkstra(i);
	}

	for (int t = 0; t < T_max; t++)
	{
		input_first();

		order_status();

		action_selection();

		output();

		reflesh();

		input_last();

		if (vertict == "NG" || t == T_max - 1)
		{
			return 0;
		}
		if (vertict == "OK" || vertict == "WAIT")
		{
			move();
		}

		sale();
	}

	int xxx;
	cin >> xxx;
}

Measured memory_bytes: 4432