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 PYTHON3):

Solution:
"""https://atcoder.jp/contests/hokudai-hitachi2019-1/tasks/hokudai_hitachi2019_1_a
Time Limit: 30 sec / Memory Limit: 1024 MB

# Score
score := time_max**2 * n_deleverd - sum((deleverd_time[i] - ordered_time[i])**2 for i in deleverd)

# Requirements
- time_max = 10_000
- 200 <= n_vertices <= 400
- 1.5*n_vertices <= n_edges <= 2*n_vertices
- 1 <= d <= ceil(4*sqrt(2*n_vertices)) <= 114

# Output
- stay ==> -1
- move x ==> x
"""

import collections
import sys

STAY = -1
BASE_POS = 0


class Order:
    def __init__(self, order_id, ordered_time, destination):
        self.order_id = order_id
        self.ordered_time = ordered_time
        self.destination = destination

    def __str__(self):
        return 'Order' + str((self.order_id, self.ordered_time, self.destination))


class Graph:
    def __init__(self, n_vertices, n_edges):
        self.n_vertices = n_vertices
        self.n_edges = n_edges
        self.adjacency_list = [[] for i in range(n_vertices)]
        self.distances = [[float('inf')] * (n_vertices)
                          for _ in range(n_vertices)]
        self.transits = [[j for j in range(n_vertices)]
                         for i in range(n_vertices)]

    def add_edge(self, u, v, d):
        self.adjacency_list[u].append((v, d))
        self.adjacency_list[v].append((u, d))
        self.distances[u][v] = d
        self.distances[v][u] = d
        self.transits[u][v] = v
        self.transits[v][u] = u

    def floyd_warshall(self):
        for i in range(self.n_vertices):
            self.distances[i][i] = 0
            self.transits[i][i] = i
        for k in range(self.n_vertices):
            for i in range(self.n_vertices):
                for j in range(self.n_vertices):
                    if self.distances[i][j] > self.distances[i][k] + self.distances[k][j]:
                        self.distances[i][j] = self.distances[i][k] + \
                            self.distances[k][j]
                        self.transits[i][j] = self.transits[i][k]


def get_orders(ordered_time):
    n_new_order = int(input())  # 0 <= n_new_order <= 1
    orders = []
    for _ in range(n_new_order):
        # 1 <= order_id <= time_max+1
        # 2 <= destination <= n_vertices
        order_id, destination = map(int, input().split())
        orders.append(Order(order_id, ordered_time, destination-1))
    return orders


def get_input():
    n_vertices, n_edges = map(int, input().split())
    graph = Graph(n_vertices, n_edges)

    for _ in range(n_edges):
        u, v, d = map(int, input().split())
        graph.add_edge(u-1, v-1, d)
    graph.floyd_warshall()

    # Floyd–Warshall algorithm

    time_max = int(input())
    orders = []
    for time_index in range(time_max):
        new_orders = get_orders(time_index)
        for order in new_orders:
            orders.append(order)
    return graph, time_max, orders


def solve(graph, time_max, orders):
    car_on_vertex = True
    car_pos = BASE_POS
    # edge_car_driving = (0, 0)
    next_pickup = 0
    commands = [-1] * time_max
    cargo = []
    t = 0
    while t < time_max:
        # pick up cargos
        if car_on_vertex and car_pos == BASE_POS:
            while next_pickup < len(orders) and orders[next_pickup].ordered_time <= t:
                cargo.append(orders[next_pickup])
                next_pickup += 1
        if cargo:
            cargo.sort(key=lambda x: (t-x.ordered_time +
                                      graph.distances[car_pos][x.destination]) ** 2)
            print(','.join([str(c) for c in cargo]), file=sys.stderr)
            dist = cargo[0].destination
            if time_max <= t + graph.distances[car_pos][dist]:
                cargo = cargo[1:]  # TODO: 高速化
                continue
            transit_point = graph.transits[car_pos][dist]
            need_time_for_move = graph.distances[car_pos][transit_point]
            for i in range(need_time_for_move):
                commands[t + i] = transit_point
            t += need_time_for_move
            car_pos = transit_point
            cargo = cargo[1:]  # TODO: 高速化
            continue
        else:
            if car_on_vertex:
                if car_pos == BASE_POS:
                    commands[t] = STAY
                else:
                    transit_point = graph.transits[car_pos][BASE_POS]
                    need_time_for_move = graph.distances[car_pos][transit_point]
                    if time_max <= t + need_time_for_move:
                        t = time_max
                        break
                    for i in range(need_time_for_move):
                        commands[t + i] = transit_point
                    t += need_time_for_move
                    car_pos = transit_point
                    continue
            else:
                pass

        commands[t] = STAY
        t += 1
    return commands


def simulate(graph, time_max, orders, commands):
    car_on_vertex = True
    car_pos = BASE_POS

    return 0


def main():
    graph, time_max, orders = get_input()
    commands = solve(graph, time_max, orders)
    for command in commands:
        if command == STAY:
            print(STAY)
        else:
            print(command+1)


if __name__ == "__main__":
    main()