import time
st_time=time.time()

from heapq import heappush, heappop
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

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

T=I()
order=[0]*T
accor=[0]*T
order_time=[]
for i in range(T):
    n=I()
    accor[i]=accor[i-1]
    if n>0:
        oid,v=MI()
        order[i]=v
        accor[i]+=1
        #order_time[v].append(i)

#show('order',order)
order_at_shop=[] # stock (vertex, order_time)
item_at_car=[[] for _ in range(V+1)] # stock order time at each vertex
 
def ship():
    #show('order_at_shop',order_at_shop)
    while order_at_shop:
        v,t=order_at_shop.pop()
        item_at_car[v].append(t)
        #show('shipped',v,'at',t)

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

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

def rand_move(s,c):
    stat_init()
    
    move=[]
    state=0 # 0 on vertex, 1 on road
    cur=1
    point=0
    
    #st=min(T//2,bisect.bisect(accor,V//2))
    #st=s+int(max( 100/(c),0 )*random.randint(0,T) )
    delta=int(T*math.exp(-c/50))
    minT=max(0,s-delta)
    maxT=min(int(0.95*T),s+delta)
    st=random.randint(minT,maxT)
    #show('---------------',st)
    
    for t in range(T):
        v=order[t]
        if v!=0:
            #show('order!',v,'at',t)
            order_at_shop.append((v,t))
        if t<st:
            move.append(-1)
            #cur_order[order[t]]+=1
            ship()
        else:
            if state==0:
                r=len(g[cur])
                dest,dist=g[cur][random.randint(0,r-1)]
                state=1
                move.append(dest)
                dist-=1
                if dist==0:
                    state=0
                    cur=dest
                    if dest==1: # 店で荷物を積載
                        ship()
                    else: # 配達完了
                        point+=deliver(dest,t)
            else:
                move.append(dest)
                dist-=1
                if dist==0:
                    state=0
                    cur=dest
    return point,st,move

#for i in range(1,V+1):
    #show(i,g[i])

time_limit=29.5 # 1 = 1 sec
#time_limit=1
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)
for i in move:
    print(i)



Measured memory_bytes: 136956