import time
st_time=time.time()

from heapq import heappush, heappop, heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)
#input=sys.stdin.readline

show_flg=False
##show_flg=True
drop_probability=1

def dijkstra(edge,st):
    # initialize: def: d=dist(st,i), prev=[previous vertex in minimum path], q[]
    n=len(edge)
    d=[(0 if st==i else inf,i) for i in range(n)]
    prev=[0]*n
    q=[i for i in d]
    heapify(q)
    
    # calc
    while q:
        dist,cur=heappop(q)
        for dst,dist in edge[cur]:
            alt=d[cur][0]+dist
            if alt<d[dst][0]:
                d[dst]=(alt,dst)
                prev[dst]=cur
                heappush(q,(alt,dst))
    dist=[i for i,j in d]
    return dist,prev

V,E=MI()
g=[[] for _ in range(V+1)]
for i in range(E):
    u,v,d=MI()
    g[u].append((v,d))
    g[v].append((u,d))

mins=[[] for _ in range(V+1)]
prevs=[[] for _ in range(V+1)]
for i in range(1,V+1):
    min_dist,prev=dijkstra(g,i)
    mins[i]=min_dist
    prevs[i]=prev

#show('mins',mins)
#show('prevs',prevs)

f=LI()
T=I()
order=[0]*T
accor=[0]*T
order_time=[]

#show('order',order)
order_at_shop=[] # stock (vertex, order_time)
item_at_car=[[] for _ in range(V+1)] # stock order time at each vertex
num_item_at_car=0

def ship():
    global num_item_at_car
    while order_at_shop:
        v,t=order_at_shop.pop()
        item_at_car[v].append(t)
        num_item_at_car+=1
##    show('item_at_car',item_at_car)

def deliver(v,deliver_t):
    global num_item_at_car
    d_p=0
    while item_at_car[v]:
        or_t=item_at_car[v].pop()
        num_item_at_car-=1
        d_p+=T**2-(deliver_t-or_t)**2
##    show("delivered to",v,"deliverPoint",d_p)
    return d_p

def stat_init():
    global order_at_shop
    global item_at_car
    global num_item_at_car
    order_at_shop=[] # stock (vertex, order_time)
    item_at_car=[[] for _ in range(V+1)] # stock order time at each vertex
    num_item_at_car=0


def neighber_search(cur,next_dest,effc,best_p,best_d,f_info=True):
    global item_at_car
    drop=[]
    n_item=0
    for nb,dist in g[cur]:
        if nb==next_dest:continue
        if len(item_at_car[nb])>n_item:
            n_item=len(item_at_car[nb])
            drop_effc=(best_p+n_item*(T**2))/(mins[cur][nb]*2+best_d)
            #if random.random()<drop_effc/effc:
            if drop_effc>=effc:
                drop=[(cur,mins[nb][cur]),(nb,mins[cur][nb])]
    return drop
    

def best_deliver(cur,now,f_info=True):
    global order_at_shop
    global item_at_car
    global num_item_at_car
    effc=0
    best_p,best_d=0,inf
    deliver_point=1
    # direct go
    for dest in range(2,V+1):
        if dest==cur:continue
        d=mins[cur][dest]
        rt=now+d
        alt=0
        for j in item_at_car[dest]:
            alt+=T**2-(rt-j)**2
        if alt/d>effc:
            effc,best_p,best_d=alt/d,alt,d
            deliver_point=dest
    # turn to shop and go
    if cur!=1:
        db=mins[cur][1]
        nx_item_at_car=[[] for i in range(1+V)]
        for order_v,t in order_at_shop:
            nx_item_at_car[order_v].append(t)
        for i in range(2,1+V):
            for t in item_at_car[i]:
                nx_item_at_car[i].append(t)
        if f_info:
            for t in range(min(now+1,T-1),min(now+db+1,T)):
                v=order[t]
                if v!=0:
                    nx_item_at_car[v].append(t)
        for dest in range(2,V+1):
            if cur==1:break
            if dest==cur:continue
            dg=mins[1][dest]
            rt=now+db+dg
            d=db+dg
            alt=0
            for j in nx_item_at_car[dest]:
                alt+=T**2-(rt-j)**2
            if alt/d>effc:
                effc,best_p,best_d=alt/d,alt,d
                deliver_point=1
            
    # generate root
    root=[]
    p=deliver_point
    while p!=cur:
        prev_p=prevs[cur][p]
        if random.random()<drop_probability: # yorimichi kakuritsu
            drop=neighber_search(cur,prev_p,effc,best_p,best_d,f_info=False)
        else:
            drop=[]
        root.append((p,mins[p][prev_p]))
        p=prev_p
    return deliver_point,root,effc


# recieve info
def interactive():
    stat_init()
    move=[]
    state=0 # 0 on vertex, 1 on road
    reached=False # True if reached at final destination
    final_dest=1
    dest=1
    cur=1
    point=0
    effc=0
    
    for t in range(T):
        Nnew=I()
        v=0
        for j in range(Nnew):
            new_id,v=MI()
        Nput=I()
        for j in range(Nput):
            put_id=I()
        
        order[t]=v
        if v!=0:
            order_at_shop.append((v,t))
        if cur==1 and state==0:
            ship()
        if num_item_at_car==0 and cur==1 and state==0:
            print(-1)
            sys.stdout.flush()
            ship()
        else:
            if state==0:
                if dest==1: # 店で荷物を積載
                    ship()
                else: # 配達完了
                    point+=deliver(dest,t)

                if cur==final_dest:
                    # set final destination
                    final_dest,root,effc=best_deliver(cur,t)
                    # end set final destination
                else:
                    0
                dest,dist=root.pop()
                state=1
            else: # on road at teh begining
                0
            print(dest)
            sys.stdout.flush()
            dist-=1
            show('moving to',dest)
            if dist==0:
                state=0
                cur=dest
        
        vardict = input()
        if vardict == 'NG':
    	    sys.exit()
        
        Nachive = int(input())
        for j in range(Nachive):
    	    achive_id=I()
    
    return          


mode='rand'
mode='greed'
if mode=='rand':
    time_limit=29.5 # 1 = 1 sec
    time_limit=0.07
    now=time.time()
    p=-1
    s=T//2
    c=1
    while True:
        c+=1
        now=time.time()
        if now - st_time > time_limit:
            break
        cur_p,cur_st,cur_move=rand_move(s,c)
        if cur_p>p or p==-1:
            p=cur_p
            s=cur_st
            move=cur_move
#        show(cur_p,cur_st,cur_move)
    
#    show('result',p,s,move)
elif mode=='greed':
    interactive()
#    show('point',point)



Measured memory_bytes: 127020