n_vertex, n_edge = gets.split.map(&:to_i)
#puts "#{n_vertex} #{n_edge}"
edges = n_vertex.times.map { Array.new(n_vertex, -1) }
for i in 0...n_edge do
  u, v, d = gets.split.map(&:to_i)
#  puts "#{u} #{v} #{d}"
  edges[u - 1][v - 1] = d
  edges[v - 1][u - 1] = d
end
#for i in 0...n_vertex do
#  puts edges[i].join(" ")
#end
f = gets.split.map(&:to_i)
#puts f.join(" ")





t_max = gets.to_i
#puts "#{t_max}"
for t in 0...t_max do
  n_new = gets.to_i
#  puts "#{n_new}"
  for i in 0...n_new do
    new_id, dst = gets.split.map(&:to_i)
#    puts "#{new_id} #{dst}"
  end
  n_put = gets.to_i
#  puts "#{n_put}"
  for i in 0...n_put do
    put_id = gets.to_i
#    puts "#{put_id}"
  end
  
  if true
    command = -1
    puts command
  end
  
  verdict = gets.chomp
  break if verdict == "NG"
  n_achieve = gets.to_i
#  puts "#{n_achieve}"
  for i in 0...n_achieve do
    achieve_id = gets.to_i
#    puts "#{achieve_id}"
  end
end
