#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;





int V, E, T;
int deri[10005];
vector<pair<int, int>> G[405];

int road[401][401];
VVI kyori(401, VI(401,INF));
VVI prever(401, VI(401, -1));
vector<vector<vector<int>>> keiro(401, vector<vector<int>>(401));

int cnt = 0;

void nyuuryoku() {
	
	//const char *fileName1 = "nyuuryoku.txt";
	//std::ifstream ci(fileName1);

	cin >> V >> E;
	REP(i, E) {
		int u, v, d;
		cin >> u >> v >> d;
		u--; v--;
		G[u].push_back({ v,d });
		G[v].push_back({ u,d });
		road[u][v] = d;
		road[v][u] = d;
	}
	cin >> T;

	REP(i, T) {
		int n;
		cin >> n;
		if (n) {
			int id, dst;
			cnt++;
			cin >> id >> dst;
			dst--;
			deri[i] = dst;
		}
	}
}


int vis[405];
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
void dijkstra(int s) {
	REP(i, V) vis[i] = 0;

	min_priority_queue<pair<ll, int>> que;

	kyori[s][s] = 0;
	que.push({ 0, s });

	while (!que.empty()) {
		auto q = que.top();
		que.pop();

		int cst = q.first;
		int cu = q.second;

		if (vis[cu]) continue;
		vis[cu] = 1;

		fore(p, G[cu]) {
			int cst2 = cst + p.second;
			int to = p.first;

			if (chmin(kyori[s][to], cst2)) {
				que.push({ kyori[s][to], to });
				prever[s][to] = cu;
			}
		}
	}
}



void get_path(int s,int t) {
	int tt = t;
	vector<int> path;

	

	while (1) {
		t = prever[s][t];
		if (s == t)break;
		path.push_back(t);
	}

	reverse(path.begin(), path.end());
	
	path.push_back(tt);

	for (int i : path) {
		keiro[s][tt] = path;
	}
}



int main() {
	//const char *fileName = "syuturyoku.txt";
	//std::ofstream cou(fileName);

	
	nyuuryoku();
	REP(i, V) {
		dijkstra(i);
	}

	REP(i, V)REP(j, V) {
		if (i == j)continue;
		get_path(i, j);
	}

	VB store(405, false);
	VB car(405, false);

	int now = 0;

	VI ans;

	VI st(405, 0);
	VI ca(405, 0);


	REP(_, T) {

		store[deri[_]] = true;
		store[0] = false;

		st[deri[_]]++;
		st[0] = 0;

		int c = 0;
		REP(i, V)c += st[i];
		if (c > 500 && _ < 9000 && now != 0) {
			while (now != 0) {
				REP(i, kyori[now][keiro[now][0][0]]) {

					ans.push_back(keiro[now][0][0] + 1);
					if (i != 0)_++;
					store[deri[_]] = true;
					st[deri[_]]++;
				}
				now = keiro[now][0][0];
			}
			continue;
		}
		if (now == 0) {
			REP(i, V) {
				if (store[i]) car[i] = true;
				store[i] = false;
				ca[i] += st[i];
				st[i] = 0;
			}
		}

		bool ch = false;
		REP(i, V) {
			if (car[i]) ch = true;
		}

		if (ch) {
			vector<pair<int, int>> v;
			REP(i, V) {
				if (car[i]) {
					v.push_back({ kyori[now][i],i });
				}
			}
			sort(ALL(v));
			int to = keiro[now][v[0].second][0];
			REP(i, kyori[now][to]) {

				ans.push_back(to + 1);
				if (i != 0)_++;
				store[deri[_]] = true;
				st[deri[_]]++;
			}
			now = to;
			car[to] = false;
			ca[to] = 0;
		}
		else if (now == 0)ans.push_back(-1);
		else {
			REP(i, kyori[now][keiro[now][0][0]]) {

				ans.push_back(keiro[now][0][0] + 1);
				if (i != 0)_++;
				store[deri[_]] = true;
				st[deri[_]]++;
			}
			now = keiro[now][0][0];
		}
	}
	while (ans.size() < 10005)ans.push_back(-1);
	REP(i, 10000)cout << ans[i] << endl;

}

Measured memory_bytes: 18048