#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <random>
#include <chrono>
#include <cassert>
using namespace std;

using ll = long long;

class timer {
private:
	chrono::system_clock::time_point start;
public:
	void set_time() {
		start = chrono::system_clock::now();
	}

	ll get_time() {
		auto end = chrono::system_clock::now();
		return chrono::duration_cast<chrono::milliseconds>(end - start).count();
	}
};

timer total_time;

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

inline double prob() {
	static const double P = (1. - 1e-5) / (unsigned)-1;
	return xor128()*P;
}

int V, E, T;
vector<vector<int>> edg, d, orgd;
struct Query { int id, dst; };
vector<vector<Query>> query;
vector<int> ans;

bool check_move(int score, int cur_score, int iter, int maxiter) {
	static const double MAXT = 3;
	static const double MINT = 1e-12;
	if (score <= cur_score) return true;
	double T = MAXT + (MINT - MAXT)*iter / maxiter;
	double p = exp((cur_score - score) / T);
	//cerr << iter << " " << T << " " << p << endl;
	return prob() < p;
}

void solve() {
	static const int MAXITER = 6000000;

	for (int k = 0; k < V; k++) {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	vector<int> ast;
	int cnt_update = 0;
	int t = 0;
	while (t < T) {
		ast.clear();
		for (int i = t; i <= min((int)ans.size(), T - 1); i++) {
			for (int j = 0; j < (int)query[i].size(); j++) {
				ast.push_back(query[i][j].dst);
			}
		}
		sort(ast.begin(), ast.end());
		ast.erase(unique(ast.begin(), ast.end()), ast.end());
		ast.push_back(0);
		const int n = (int)ast.size();

		int cur_score = d[0][ast[0]];
		for (int i = 0; i < n - 1; i++) {
			cur_score += d[ast[i]][ast[i + 1]];
		}
		int gscore = cur_score;

		if (n >= 3) {
			for (int iter = 0; iter < MAXITER; iter++) {
				int ia = xor128() % n, ib = xor128() % n;
				if (ia > ib) swap(ia, ib);
				if (ib - ia <= 1) {
					iter--;
					continue;
				}

				reverse(ast.begin() + ia, ast.begin() + ib);

				int score = d[0][ast[0]];
				for (int i = 0; i < n - 1; i++) {
					score += d[ast[i]][ast[i + 1]];
				}

				if (check_move(score, cur_score, iter, MAXITER)) {
					if (score < gscore) {
						cnt_update++;
					}
					cur_score = score;
					gscore = min(gscore, score);
				}
				else {
					reverse(ast.begin() + ia, ast.begin() + ib);
				}
			}
		}

		t = ans.size();
		int pos = 0;
		for (int tg : ast) {
			while (pos != tg) {
				for (int eid = 0; eid < (int)edg[pos].size(); eid++) {
					const int e = edg[pos][eid];
					const int de = orgd[pos][eid];
					if (de + d[e][tg] == d[pos][tg]) {
						for (int j = 0; j < de; j++) {
							ans.push_back(e);
						}
						pos = e;
						break;
					}
				}
			}
		}

		while (ans.size() < t + 1) {
			ans.push_back(-2);
		}
	}

	cerr << "update " << cnt_update << endl;
}

void input() {
	cin >> V >> E;
	edg.resize(V);
	orgd.resize(V);
	d = vector<vector<int>>(V, vector<int>(V, 1e9));
	for (int i = 0; i < V; i++) d[i][i] = 0;
	for (int i = 0; i < E; i++) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		edg[a].push_back(b);
		edg[b].push_back(a);
		orgd[a].push_back(c);
		orgd[b].push_back(c);
		d[a][b] = d[b][a] = c;
	}
	cin >> T;
	query.resize(T);
	for (int t = 0; t < T; t++) {
		int n; cin >> n;
		for (int i = 0; i < n; i++) {
			int a, b; cin >> a >> b;
			b--;
			query[t].push_back({ a, b });
		}
	}
}

void output() {
	for (int i = 0; i < T; i++) {
		if (i < ans.size()) cout << ans[i] + 1 << endl;
		else cout << -1 << endl;
	}
}

int main() {
	total_time.set_time();
	input();
	solve();
	output();
	cerr << total_time.get_time() << " ms" << endl;
	return 0;
}

// 475627842439, 465867452248


Measured memory_bytes: 1664