#!/usr/bin/env python
from collections import defaultdict
import random
import sys
from functools import lru_cache

class Maps(object):
    def __init__(self):
        self.readinputs()

    # recieve |V| and |E|
    def readinputs(self):
        self.V, self.E = map(int, input().split())
        self.es = [[] for i in range(self.V)]
        self.Mes = [[0]*self.V for i in range(self.V)]
        self.graph = Graph()
        self.car = Car()
        self.plan = []
        self.info_id = dict()

        for _ in range(self.E):
            # recieve edges
            a, b, c = map(int, input().split())
            a, b = a-1, b-1
            self.es[a].append((b,c))
            self.es[b].append((a,c))
            self.Mes[a][b] = c
            self.Mes[b][a] = c
            self.graph.add_edge(a,b,c)

        self.F = list(map(int, input().split()))
        self.T = int(input())
        self.info = [[] for i in range(self.T)]

    def has_plan(self):
        if self.plan == []:
            return False
        else:
            return True
                
    def next_place(self, here, command):
        if command == -2:
            return here
        else:
            to = command
            if here[0] == 'v':
                dist = self.Mes[here[1]][to]
                if dist == 0:
                    raise ValueError('Dist has not 0')                
                elif dist == 1:
                    return ('v', to)
                else:
                    return ('e', here[1], to, 1) # You can move 1m per time
            elif here[0] == 'e':
                if here[2] == to:
                    if here[3] + 1 < self.Mes[here[1]][here[2]]:
                        return ('e', here[1], here[2], here[3] + 1)
                    elif here[3] + 1 == self.Mes[here[1]][here[2]]:
                        return ('v', here[2])
                    else:
                        raise ValueError('Distance error!')

                elif here[1] == to:
                    if here[3] - 1 > 0:
                        return ('e', here[1], here[2], here[3] - 1)
                    elif here[3] - 1 == 0:
                        return ('v', here[1])
                    else:
                        raise ValueError('Distance error!')
            else:
                raise ValueError('Here has vertex or edge status')

    def get_command(self, here, plan):
        if here[0] == 'v':
            # you are in vertex
            if plan == []:
                # stay at 0
                return -2
            elif here[1] == plan[-1]:
                # arrive goal
                return -2
            else:
                return plan[plan.index(here[1]) + 1]
        elif here[0] == 'e':
            # you are in edge
            return here[2]
        else:
            raise ValueError('Here has vertex or edge status')
            
    def output(self, t):
        out = self.path[t] + 1
        print(str(out), flush=True)
        # print("-1", flush=True)

    def judge(self):
        vardict = input()
        if vardict == 'NG':
            sys.exit()

        Nachieve = int(input())
        for _ in range(Nachieve):
            achive_id = int(input())
            self.car.unload_id(achive_id)

    def select_goal(self, here, dests):
        dist = dict()
        for dest in dests:
            path = wrap_dijsktra(self.graph, here, dest)
            dist[dest] = self.dist_path(path)
        nearby = min(dist, key=dist.get)
        return nearby

    def select_goal_bytime(self, here, dests):
        return dests[0]

    def dist_path(self, path):
        distance = 0
        for n in range(len(path)-1):
            distance += self.Mes[path[n]][path[n+1]]
        return distance

    def recieve_info(self):
        # recieve info
        Nnew = int(input())
        for _ in range(Nnew):
            new_id, dst = map(int, input().split())
            dst = dst-1
            self.info_id[new_id] = dst
        Nput = int(input())
        for _ in range(Nput):
            put_id = int(input())
            self.car.pickup_id(put_id)

    def run(self):
        where = [('v', 0)] # ('v', here) or ('e', from, to, dist)
        self.path = [0]*self.T

        for t in range(self.T):
            now_where = where[-1]
            self.recieve_info()
            
            if self.car.id_box == []:
                if now_where[0] == 'v' and now_where[1] == 0:
                    self.path[t] = -2
                    self.output(t)
                    self.judge()
                    continue

            if not self.has_plan():
                if self.car.id_box == []:
                    goal = 0
                else:
                    goal = self.info_id[self.car.id_box[0]]
                    # goal = self.select_goal_bytime(now_where[1], self.car.show_dest(self.info_id))
                self.plan = wrap_dijsktra(self.graph, now_where[1], goal)

            if self.plan == []:
                self.path[t] = -2
                self.output(t)
                self.judge()
                continue

            command = self.get_command(now_where, self.plan)
            self.path[t] = command
            where.append(self.next_place(now_where, command))
            
            if where[-1][0] == 'v' and where[-1][1] == self.plan[-1]:
                self.plan = []

            self.output(t)
            self.judge()

class Graph():
    def __init__(self):
        self.edges = defaultdict(list)
        self.weights = {}
    
    def add_edge(self, from_node, to_node, weight):
        # Note: assumes edges are bi-directional
        self.edges[from_node].append(to_node)
        self.edges[to_node].append(from_node)
        self.weights[(from_node, to_node)] = weight
        self.weights[(to_node, from_node)] = weight

class Car(object):
    def __init__(self):
        # self.box = []
        # self.dest = set()
        self.id_box = []
    
    def pickup_id(self, parcel_id):
        if parcel_id == []:
            pass
        else:
            self.id_box.append(parcel_id)

    def unload_id(self, vertex):
        self.id_box = [x for x in self.id_box if x != vertex]
        # self.dest = {x for x in self.box if x[1] != vertex}
 
    def show_dest(self, info_id):
        dest = set()
        for x in self.id_box:
            dest.add(info_id[x])
        if len(dest) == 0:
            dest.add(0)
        return list(dest)


def wrap_dijsktra(graph, initial, end):
    if initial == end:
        return []
    elif initial < end:
        return dijsktra(graph, initial, end)
    else:
        return dijsktra(graph, end, initial)[::-1]

@lru_cache(maxsize=80000)
def dijsktra(graph, initial, end):
    # shortest paths is a dict of nodes
    # whose value is a tuple of (previous node, weight)
    shortest_paths = {initial: (None, 0)}
    current_node = initial
    visited = set()
    
    while current_node != end:
        visited.add(current_node)
        destinations = graph.edges[current_node]
        weight_to_current_node = shortest_paths[current_node][1]

        for next_node in destinations:
            weight = graph.weights[(current_node, next_node)] + weight_to_current_node
            if next_node not in shortest_paths:
                shortest_paths[next_node] = (current_node, weight)
            else:
                current_shortest_weight = shortest_paths[next_node][1]
                if current_shortest_weight > weight:
                    shortest_paths[next_node] = (current_node, weight)
        
        next_destinations = {node: shortest_paths[node] for node in shortest_paths if node not in visited}
        if not next_destinations:
            return "Route Not Possible"
        # next node is the destination with the lowest weight
        current_node = min(next_destinations, key=lambda k: next_destinations[k][1])
    
    # Work back through destinations in shortest path
    path = []
    while current_node is not None:
        path.append(current_node)
        next_node = shortest_paths[current_node][0]
        current_node = next_node
    # Reverse path
    path = path[::-1]
    return path

if __name__ == "__main__":
    def main():
        M = Maps()
        M.run()

    main()


Measured memory_bytes: 9884