// とりあえず 30 s 使うだけ

#ifndef TIMER_H
#define TIMER_H

#include <cstdint>

#ifdef ONLY_MY_ENVIR

#include <chrono>
class Timer {
	const std::chrono::time_point<std::chrono::system_clock> start;
	int64_t limit_microsec = 0;

public:
	Timer();
	void set(int64_t time_microsec);
	bool elapsed() const;
	int64_t getMicrosec() const;
};

#else

class Timer {
	static const uint64_t ClocksPerMicrosec;
	const uint64_t start_clocks;
	uint64_t limit_clocks;

	uint64_t getClocks() const;
public:
	Timer();
	void set(int64_t time_microsec);
	bool elapsed() const;
	int64_t getMicrosec() const;
};

#endif

#endif

#ifdef ONLY_MY_ENVIR
#include "Timer.h"
#endif

#ifdef ONLY_MY_ENVIR

using namespace std::chrono;

Timer::Timer()
	: start(system_clock::now()) {
}

void Timer::set(int64_t time_microsec) {
	limit_microsec += time_microsec;
}

bool Timer::elapsed() const {
	return getMicrosec() >= limit_microsec;
}

int64_t Timer::getMicrosec() const {
	return duration_cast<microseconds>(system_clock::now() - start).count();
}

#else

const uint64_t Timer::ClocksPerMicrosec = 2790;

uint64_t Timer::getClocks() const {
	unsigned int lo, hi;
	__asm__ volatile ("rdtsc" : "=a" (lo), "=d" (hi));
	return ((uint64_t)hi << 32) | lo;
}

Timer::Timer() 
	: start_clocks(getClocks()), limit_clocks(start_clocks) {
}

void Timer::set(int64_t time_microsec) {
	limit_clocks += time_microsec * ClocksPerMicrosec;
}

bool Timer::elapsed() const {
	return getClocks() >= limit_clocks;
}

int64_t Timer::getMicrosec() const {
	return (getClocks() - start_clocks) / ClocksPerMicrosec;
}

#endif

#ifndef RANDOM_H
#define RANDOM_H

#include <cstdint>

uint32_t rnd();
uint32_t rnd(uint32_t max);

#endif

#ifdef ONLY_MY_ENVIR
#include "Random.h"
#endif

uint32_t rnd() {
	static uint32_t val = 3141592653ul;
	val ^= val << 13;
	val ^= val >> 17;
	val ^= val << 15;
	return val;
}

uint32_t rnd(uint32_t max) {
	return rnd() % max;
}

#ifndef __GLOBAL_H__
#define __GLOBAL_H__

#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>

#define REP(i, a, n) for(int i = (a), i##_max_ = (n); i < i##_max_; ++i)
#define REM(i, a, n) for(int i = (int)(n) - 1, i##min_ = (a); i >= i##min_; --i)

template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) {
	fill(dest, dest + N, val);
}

template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) {
	for (int i = 0; i < M; ++i) {
		Fill(dest[i], val);
	}
}

template <class T>
T read(std::istream& ist) {
	T buffer;
	ist >> buffer;
	return buffer;
}

using Edge = std::pair<int, int>;
using Graph = std::vector<std::vector<Edge>>;
using Command = int;
using Path = std::vector<int>;
using Score = int64_t;

template <class T>
using Matrix = std::vector<std::vector<T>>;

struct Order {
	int t;
	int id;
	int v;

	Order() = default;
	Order(int t, int id, int v)
		: t(t), id(id), v(v) {
	}
};

Graph readGraph(std::istream& ist);
std::vector<Order> readOrders(std::istream& ist, int t_max);
std::vector<Order> readOrdersOneTurn(std::istream& ist, int t);
void writeCommand(std::ostream& ost, Command command);
std::pair<Matrix<int>, Matrix<Path>> findShortestPaths(const Graph& graph);

#endif

#ifdef ONLY_MY_ENVIR
#include "Global.h"
#endif

Graph readGraph(std::istream& ist) {
	int N, M;
	ist >> N >> M;

	Graph ret(N);
	REP(j, 0, M) {
		int a, b, c;
		ist >> a >> b >> c;
		--a; --b;
		ret[a].push_back(Edge(b, c));
		ret[b].push_back(Edge(a, c));
	}

	return ret;
}

std::vector<Order> readOrders(std::istream& ist, int t_max) {
	std::vector<Order> ret;
	REP(t, 0, t_max) {
		auto orders = readOrdersOneTurn(ist, t);
		for (const Order& order : orders) {
			ret.push_back(order);
		}
	}
	return ret;
}

std::vector<Order> readOrdersOneTurn(std::istream& ist, int t) {
	std::vector<Order> ret;
	int k;
	ist >> k;
	REP(i, 0, k) {
		int id, v;
		ist >> id >> v;
		--v;
		ret.push_back(Order(t, id, v));
	}
	return ret;
}

void writeCommand(std::ostream& ost, Command command) {
	if (command == -1) {
		ost << -1 << std::endl;
	} else {
		ost << command + 1 << std::endl;
	}
}


std::pair<Matrix<int>, Matrix<Path>> findShortestPaths(const Graph& graph) {
	auto subFunc = [](const Graph& graph, int start) -> std::pair<std::vector<int>, std::vector<Path>> {
		const int N = graph.size();
		const int inf = 1e9;
		using State = std::tuple<int, int, int>;
		std::priority_queue<State, std::vector<State>, std::greater<State>> que;

		std::vector<int> dists(N, inf);
		std::vector<int> prevs(N, -1);
		que.push(State(0, start, -1));
		while (!que.empty()) {
			auto p = que.top(); que.pop();
			int dist = std::get<0>(p);
			int from = std::get<1>(p);
			int prev = std::get<2>(p);
			if (dists[from] != inf) continue;
			dists[from] = dist;
			prevs[from] = prev;
			for (auto e : graph[from]) {
				int to = e.first;
				int cost = e.second;
				que.push(State(dist + cost, to, from));
			}
		}

		std::vector<Path> paths;
		REP(i, 0, N) {
			Path path;
			int curr = i;
			while (curr != start) {
				path.push_back(curr);
				curr = prevs[curr];
			}
			std::reverse(path.begin(), path.end());
			paths.emplace_back(std::move(path));
		}
		return std::make_pair(dists, paths);
	};

	const int N = graph.size();
	Matrix<int> dist_mat;
	Matrix<Path> path_mat;

	REP(start, 0, N) {
		auto pair = subFunc(graph, start);
		dist_mat.emplace_back(std::move(pair.first));
		path_mat.emplace_back(std::move(pair.second));
	}

	return std::make_pair(dist_mat, path_mat);
}

#ifndef __TSP_H__
#define __TSP_H__

#ifdef ONLY_MY_ENVIR
#include "Random.h"
#include "Global.h"
#endif

class TSPOracle {
	std::vector<int> state;
	int score;
	int estim_score;

	const int size;
	const Matrix<int> dist_mat;

	struct Memo {
		int l;
		int r;
	} memo;

public:
	TSPOracle(const Matrix<int>& dist_mat);
	int estimate();
	void transition();
	int getScore() const;
	std::vector<int> get() const;

private:
	int calc() const;
};

std::vector<int> solveTSP(const Matrix<int>& dist_mat);

#endif

#ifdef ONLY_MY_ENVIR
#include "TSP.h"
#include "Timer.h"
#endif

TSPOracle::TSPOracle(const Matrix<int>& dist_mat)
	: size(dist_mat.size()), dist_mat(dist_mat) {

	REP(i, 0, size) {
		state.push_back(i);
	}
	state.push_back(0);
	score = calc();
}

int TSPOracle::estimate() {
	int l;
	int r;
	do {
		l = rnd(size) + 1;
		r = rnd(size) + 1;
	} while (l == r);
	if (l > r) std::swap(l, r);

	memo.l = l;
	memo.r = r;

	int u0 = state[l - 1];
	int u1 = state[l];
	int v0 = state[r - 1];
	int v1 = state[r];

	int delta = 0;
	delta -= dist_mat[u0][u1] + dist_mat[v0][v1];
	delta += dist_mat[u0][v0] + dist_mat[u1][v1];
	
	estim_score = score + delta;
	return -delta;
}

void TSPOracle::transition() {
	std::reverse(state.begin() + memo.l, state.begin() + memo.r);
	score = estim_score;
}

int TSPOracle::getScore() const {
	return score;
}

std::vector<int> TSPOracle::get() const {
	std::vector<int> ret(state);
	ret.erase(ret.begin());
	return ret;
}

int TSPOracle::calc() const {
	int sum = 0;
	REP(i, 0, size) {
		int from = state[i];
		int to = state[i + 1];
		sum += dist_mat[from][to];
	}
	return sum;
}

std::vector<int> solveTSP(const Matrix<int>& dist_mat) {
	Timer timer;

	// 最適化
	TSPOracle oracle(dist_mat);
	constexpr int time_limit = 29000000;
	constexpr double tmp_start = 1e4;
	constexpr double tmp_finish = 0.02;
	double tmp = tmp_start;

	int z = 0;
	timer.set(time_limit);
	while (z % 512 != 0 || !timer.elapsed()) {
		++z;
		if (z % 4096 == 0) {
			double ratio = double(timer.getMicrosec()) / time_limit;
			tmp = tmp_start * std::pow(tmp_finish / tmp_start, ratio);
#if ONLY_MY_ENVIR
			//std::cerr << tmp << ' ' << oracle.getScore() << std::endl;
#endif
		}

		Score delta = oracle.estimate();
		bool accepted = delta >= 0
			|| -delta <= 8 * tmp && rnd() < std::exp(delta / tmp) * (1ll << 32);

		if (accepted) {
			oracle.transition();
		}
	}

	std::cerr << oracle.getScore() << std::endl;
	auto state = oracle.get();
	
	return state;
}
#ifndef __PROBLEM_B_H__
#define __PROBLEM_B_H__

#ifdef ONLY_MY_ENVIR
#include "Global.h"
#endif

using Freq = int;
using Freqs = std::vector<Freq>;

void problemB();
void readLoading(std::istream& ist);
bool readVerdict(std::istream& ist);

class ManagerB {
	std::vector<Command> commands;

	const Graph graph;
	const Freqs freqs;
	const int t_max;

public:
	ManagerB(const Graph& graph, const Freqs& freqs, int t_max);
	void precalc();
	Command step(const std::vector<Order>& orders_turn);
};

#endif

#ifdef ONLY_MY_ENVIR
#include "problemB.h"
#include "Timer.h"
#include "TSP.h"
#endif

using std::cin;
using std::cout;

void problemB() {
	Graph graph = readGraph(cin);
	std::vector<int> freqs;
	REP(i, 0, graph.size()) {
		freqs.push_back(read<int>(cin));
	}

	int t_max = read<int>(cin);

	ManagerB manager(graph, freqs, t_max);
	REP(t, 0, t_max) {
		auto orders_turn = readOrdersOneTurn(cin, t);
		readLoading(cin);		// ignore
		Command command = manager.step(orders_turn);
		writeCommand(cout, command);
		bool is_correct = readVerdict(cin);
		if (!is_correct) return;
	}
	return;
}

void readLoading(std::istream& ist) {
	int n;
	ist >> n;
	REP(z, 0, n) {
		int buf;
		ist >> buf;
	}
}

bool readVerdict(std::istream& ist) {
	std::string verdict = read<std::string>(ist);
	if (verdict != "OK") return false;
	int k;
	ist >> k;
	REP(z, 0, k) {
		int id;
		ist >> id;
	}
	return true;
}

ManagerB::ManagerB(const Graph& graph, const Freqs& freqs, int t_max) 
	: graph(graph), freqs(freqs), t_max(t_max) {
	precalc();
}

void ManagerB::precalc() {
	auto pair = findShortestPaths(graph);
	Matrix<int> dist_mat = pair.first;
	Matrix<Path> path_mat = pair.second;

	/* 巡回ルートを決める */
	auto route = solveTSP(dist_mat);
	
	int t_required = 0;
	std::vector<int> path_opt;		// 隣接点のみで構成されるパス
	int v_curr = 0;
	for (int v : route) {
		t_required += dist_mat[v_curr][v];
		for (int to : path_mat[v_curr][v]) {
			path_opt.push_back(to);
		}
		v_curr = v;
	}

	/* 行動を決定 */
	int times = t_max / t_required;
	int rest = t_max % t_required;

	REP(z, 0, rest) {
		commands.push_back(-1);
	}

	REP(z, 0, times) {
		int v_curr = 0;
		for (int v : path_opt) {
			int dist = dist_mat[v_curr][v];
			REP(x, 0, dist) {
				commands.push_back(v);
			}
			v_curr = v;
		}
	}
	assert(commands.size() == t_max);
}

Command ManagerB::step(const std::vector<Order>& orders_turn) {
	static int turn = 0;
	Command command = commands[turn];
	++turn;
	return command;
}
#ifndef __MAIN_H__
#define __MAIN_H__

#ifdef ONLY_MY_ENVIR
#include "Global.h"
#include "Random.h"
#endif

#endif

#ifdef ONLY_MY_ENVIR
#include "Main.h"
#include "ProblemA.h"
#include "ProblemB.h"
#endif

/* V <= 400, E <= 800, D <= 114 */

int main() {
	problemB();
	return 0;
}



Measured memory_bytes: 34764