Problem: Requirements

* All inputs are of non-negative integer value.
* T_{\text{max}} = 10000
* 200 \leq |V| \leq 400
* 1.5 |V| \leq |E| \leq 2 |V|
* 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|)
* 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil (1 \leq i \leq |E|)
* The given graph has no self-loops / multiple edges and is guaranteed to be connected.
* 0 \leq N_{\text{new}} \leq 1
* 1 \leq \mathrm{new\\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{new}}). Note: If all orders are generated by the order generation rule as explained above, the total number of orders is at most T_{\text{last}}+1. Therefore, the possible range of \mathrm{new\\_id}_{i} should be from 1 to T_{\text{last}}+1.
* 2 \leq \mathrm{dst}_i \leq |V| (1 \leq i \leq N_{\text{new}})
* The order IDs \mathrm{new\\_{id}}_i are unique.

Input Format

Input is provided in the following form:


|V| |E|
u_{1} v_{1} d_{u_{1}, v_{1}}
u_{2} v_{2} d_{u_{2}, v_{2}}
:
u_{|E|} v_{|E|} d_{u_{|E|}, v_{|E|}}
T_{\text{max}}
\mathrm{info}_{0}
\mathrm{info}_{1}
:
\mathrm{info}_{T_{\text{max}}-1}


* In the first line |V| denotes the number of vertices, while |E| denotes the number of edges.
* The following |E| lines denote the edges of the graph. In particular, in the ith line u_{i} and v_{i} denote the edge connecting u_{i} and v_{i} and d_{u_{i}, v_{i}} the corresponding distance.
* The following line denotes the number of steps T_{\text{max}}.



In the following line, \mathrm{info}_t is information about the order from the customer that occurs at time t. \mathrm{info}_t is given in the form:


N_{\text{new}}
\mathrm{new\_id}_1 \mathrm{dst}_1
\mathrm{new\_id}_2 \mathrm{dst}_2
\vdots
\mathrm{new\_id}_{N_{\text{new}}} \mathrm{dst}_{N_{\text{new}}}


* N_{\text{new}} represents the number of new orders which appear at time t.
* The next N_{\text{new}} lines give the newly generated order information. The i-th order information indicates that the order ID \mathrm{new\\_{id}}_i of the new order, while \mathrm{dst}_i denotes the vertex to which the customer wishes the order to be delivered.
* Note: If N_{\text{new}}=0, there are no new lines.

Output Format

The Output expects T_{\text{max}} integers in the format specified below.


\mathrm{command}_{0}
\mathrm{command}_{1}
:
\mathrm{command}_{T_{\text{max}}-1}


In particular, \mathrm{command}_{i} shall specify the movement of the delivery car by using one of the following two options:

1) `stay`, if the car shall not move:


-1


2) `move w`, if the car shall be moved one step towards the neighboring vertex w


w


Note that in case of 2) w has to satisfy the following conditions:

* w \in V
* If the car is at vertex u: \left\\{ u, w \right\\} \in E .
* If the car is on the edge \left\\{ u, v \right\\}, w must either satisfy u = w or v = w.



* * *

Examples

Input




Output




Input

5 7
1 2 5
5 3 4
2 4 8
1 5 1
2 3 3
4 5 3
4 3 9
4
1
1 2
1
2 5
1
3 4
0


Output

2
-1
1
5

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(int (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(int (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1e9+5;
const ll LINF = 1e18+5;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;
const int MAX_T = 1e5;
const int MAX_V = 400;
const int TRIALS = 500;
int V, E, T;
int time_div = 0;

struct Player{
	int pos;
	int dst;
	int nxt;
	int rest;
};

struct Task{
	int id;
	int dst;
	int time;
	int score(int t){
		return T*T-(t-time)*(t-time);
	}
};

int dist[MAX_V+1][MAX_V+1] = {};
ll ans_score = 0, score = 0;
Player player = {1, 1, 1, 0};
vector<vector<Task> > task_list(MAX_T);
vector<int> command(MAX_T);
vector<int> ans_command(MAX_T);
vector<Task> ordered_tasks;
vector<vector<Task> > recieved_tasks(MAX_V+1);

void print_vec(const vector<Task> v){
	for(Task i : v) cosp(i.id);
	cout << endl;
}

void print_dist(){
	repn(i, V){
		repn(j, V) cosp(dist[i][j]);
		cout << endl;
	}
}

void list_tasks(int t){
	int n;
	cin >> n;
	rep(i, n){
		Task tmp;
		cin >> tmp.id >> tmp.dst;
		tmp.time = t;
		task_list[t].pb(tmp);
	} 
}

void init(){
	player = {1, 1, 1, 0};
	ordered_tasks.clear();
	repn(i, V) recieved_tasks[i].clear();
	score = 0;
}

void init_dist(){
	repn(i, V) repn(j, V) dist[i][j] = INF;
	repn(i, V) dist[i][i] = 0;
}

void input(){
	cin >> V >> E;
	init_dist();
	rep(i, E){
		int v1, v2, d;
		cin >> v1 >> v2 >> d;
		dist[v1][v2] = d;
		dist[v2][v1] = d;
	}
	cin >> T;
	rep(i, T) list_tasks(i);
}

void output(){
	rep(i, T) co(ans_command[i]);
}

void wf(){
	repn(k, V) repn(i, V) repn(j, V) dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
}

void order_task(int t){
	ordered_tasks.insert(ordered_tasks.end(), all(task_list[t]));
}

void recieve_task(){
	rep(i, ordered_tasks.size()){
		Task tmp = ordered_tasks[i];
		recieved_tasks[tmp.dst].pb(tmp);
	}
	ordered_tasks.clear();
}

void dicide_dst(int t){
	if(!recieved_tasks[player.pos].empty()){
		rep(i, recieved_tasks[player.pos].size()) score += recieved_tasks[player.pos][i].score(t);
		recieved_tasks[player.pos].clear();
	}
	player.dst = 1;
	//if(player.pos == 1 && !task_list[t+1].empty() && t < 5000) return;
	int min_dist = INF;
	if(player.pos != 1 && !ordered_tasks.empty()) min_dist = dist[player.pos][1];
	repn(i, V){
		if(recieved_tasks[i].empty()) continue;
		int d = dist[player.pos][i];
		if(time_div) rep(j, recieved_tasks[i].size()) d -= (t-recieved_tasks[i][j].time)/time_div;
		if(d < min_dist){
			min_dist = d;
			player.dst = i;
		}
	}
}

void search_nxt(){
	player.nxt = player.dst;
	bool flg = true;
	while(flg){
		flg = false;
		repn(i, V){
			if(i == player.nxt || i == player.pos) continue;
			if(dist[player.pos][player.nxt] == dist[player.pos][i]+dist[i][player.nxt]){
				player.nxt = i;
				flg = true;
				break;
			}
		}
	}

	player.rest = dist[player.pos][player.nxt];
}

void move(int t){
	if(player.pos == player.nxt){
		search_nxt();
	}
	if(player.rest){
		player.rest--;
		command[t] = player.nxt;
		if(!player.rest) player.pos = player.nxt;
	}else command[t] = -1;
}

void action(int t){
	order_task(t);
	if(player.pos == 1 && player.nxt == 1) recieve_task();
	if(player.pos == player.dst) dicide_dst(t);
	move(t);
}

void copy_command(){
	rep(i, T) ans_command[i] = command[i];
}

void solve(){
	init();
	rep(i, T) action(i);
}

int main(void){
	/*
	ifstream ifs("./inout/input1.in");
	cin.rdbuf(ifs.rdbuf());
	ofstream ofs("./inout/output.out");
	streambuf* buf = cout.rdbuf(ofs.rdbuf());
	*/
	input();
	wf();
	rep(i, TRIALS){
		solve();
		if(score > ans_score){
			copy_command();
			ans_score = score;
		}
		time_div += 10;
	}
	output();
	//cout.rdbuf(buf);
	//co(ans_score);
	return 0;
}