#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <utility>
#include <memory>
#include <cassert>
#include <initializer_list>

using namespace std;

// ビーム幅
constexpr int BEAM_WIDTH = 2600;

struct NodePast {
	// 現在のノード、現在のスコア、経過時間、最後に店に戻ったTime、積んでいる荷物の総量
	int current, elapsed_time;
	shared_ptr<NodePast> prev;
	
	NodePast(int current, int elapsed_time)
	: current(current), elapsed_time(elapsed_time) {
	}
};

struct Node : NodePast {
	// 現在のスコア、経過時間、最後に店に戻ったTime、積んでいる荷物の総量
	int score, last_visited, sum_order;
	// 届け先ごとの積んでいる荷物の量
	vector<int> orders;
	
	Node(int current, int elapsed_time, int score, int last_visited, int sum_order)
	: NodePast(current, elapsed_time)
	, score(score), last_visited(last_visited), sum_order(sum_order) {
	}
	
	bool operator < (const Node& target) const {
		return score < target.score;
	}
	
	bool operator > (const Node& target) const {
		return score > target.score;
	}

};

// pasted from http://koturn.hatenablog.com/entry/2018/06/10/060000
template<typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
[[nodiscard]]
#elif defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
#endif  // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
FixPoint : private F
{
public:
  explicit constexpr FixPoint(F&& f) noexcept
    : F(std::forward<F>(f))
  {}
 
  template<typename... Args>
  constexpr decltype(auto)
  operator()(Args&&... args) const
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
    noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...)))
#endif  // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};  // class FixPoint
 
 
template<typename F>
static inline constexpr decltype(auto)
makeFixPoint(F&& f) noexcept
{
  return FixPoint<F>{std::forward<F>(f)};
}
 
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});
	}
	
	int Tmax; std::cin >> Tmax;
	vector<vector<int>> orders(Tmax + 1);

	// recieve info
	for(int i = 0; i < Tmax; i++) {
		int Nnew; std::cin >> Nnew;
		for(int j = 0; j < Nnew; j++) {
			int new_id, dst; std::cin >> new_id >> dst;
			
			// We don't use new_id
			orders[i].push_back(dst);
		}
	}

	// insert your code here to get more meaningful output
	auto solve = [&, V, Tmax]() {
	 	Node best(0, Tmax, -16777216, Tmax, 0);
	 		  
	  	// その場を動かないノード（自己ループ）を追加
		for (int i = 0; i < V; i++)
			G[i].emplace_back(i, 1);
			
		priority_queue<Node> beam, next_beam;
		
	 	Node tmp(0, 0, 0, 0, 0);
		tmp.orders.resize(V + 1, 0);
		for (int j : orders[0])
			tmp.orders[j]++;
		tmp.sum_order += (int)orders[0].size();
		beam.push(move(tmp));
		
		for(int h = 0; h < Tmax; h++) {
			vector<int> found(V, 0);
			
			for (int i = 0; i < BEAM_WIDTH && !beam.empty(); i++) {
				const auto current_node = beam.top(); beam.pop();
				auto current_ptr = make_shared<NodePast>(current_node);
				
				if (found[current_node.current] >= 4) {
					// 二度目は探索しない
					i--;
					continue;
				}
				else
					found[current_node.current]++;
					
				for (const auto& j : G[current_node.current]) {
					Node new_node = current_node;
					
					new_node.current = j.first;
					new_node.elapsed_time += j.second;
					if (new_node.elapsed_time <= Tmax) {
						new_node.sum_order -= new_node.orders[j.first];
						const int base_score = new_node.orders[j.first] * (4096 - 16) - j.second;
						new_node.score += base_score;
						new_node.orders[j.first] = 0;
						
						if (j.first == 0) {
							for (int k = new_node.last_visited + 1; k <= new_node.elapsed_time; k++) {
								for (int l : orders[k])
									new_node.orders[l]++; 
								new_node.sum_order += (int)orders[k].size();
								new_node.score += (int)orders[k].size() * 16;	
							}
							new_node.last_visited = new_node.elapsed_time;
						}
						new_node.prev = current_ptr;
						next_beam.push(move(new_node));
					}
					else if (current_node > best)
						best = current_node;
				}
			}
			
			beam = move(next_beam);
			next_beam = decltype(next_beam)();	// priority_queue has no clear method...
		}
		
		int Tnow = 0, nodePrev = -1;
		auto write = makeFixPoint([&Tnow, &nodePrev](auto f, NodePast& node) -> void {
			if (node.prev)
				f(*node.prev);
			
			if (nodePrev == node.current)
				node.current = -1 - 1;
			else
				nodePrev = node.current;
				
			while (Tnow < node.elapsed_time) {
				cout << node.current + 1 << endl;
                Tnow++;
            }
		});
	
		// all stay
		write(best);
		assert(Tnow <= Tmax);
		for(int i = Tnow; i < Tmax; i++) std::cout << -1 << std::endl;
	};
	
  	solve();
	return 0;
}







Measured memory_bytes: 20176