using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AtCoder
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            checked
            {
                var first = new FirstInput();

                var graph = BuildGraph(first);
                Car car = new Car();
                var remineOdrs = new List<Order>();

                for (int i = 0; i < first.Tmax; i++)
                {
                    var order = new OrdersInput();
                    if (order.order != null) remineOdrs.Add(order.order);

                    Console.WriteLine(Drive(graph, car, remineOdrs));

                    var verdict = new VerdictInput();
                    if (verdict.verdict != "OK") break;

                    remineOdrs.RemoveAll(o => verdict.archives.Contains(o.id));
                }
            }
        }

        private static string Drive(List<Vertex> graph, Car car, List<Order> remineOdrs)
        {
            if (car.Returned)
            {
                if (remineOdrs.Count == 0) return "-1";
                car.SetDest(remineOdrs[0].dst);
            }
            else if (car.Arrived)
            {
                car.Return();
            }

            return car.Drive(graph);
        }

        private static List<Vertex> BuildGraph(FirstInput f)
        {
            var template = new int[f.sizeV];
            for (int i = 0; i < template.Length; i++) template[i] = int.MaxValue - 65535;

            var vertices = Enumerable
                .Range(0, f.sizeV)
                .Select(n => new Vertex(n, (int[])template.Clone()))
                .ToList();

            foreach (var side in f.sides)
            {
                var u = vertices[side.u];
                var v = vertices[side.v];
                u.Adjacent.Add(Tuple.Create(v, side.distance));
                v.Adjacent.Add(Tuple.Create(u, side.distance));
            }

            foreach (var start in vertices)
            {
                start.Distances[start.Id] = 0;

                var queue = new Queue<Vertex>();
                queue.Enqueue(start);

                while (queue.Count > 0)
                {
                    var vertex = queue.Dequeue();

                    if (vertex != start)
                    {
                        vertex.Distances[start.Id] = vertex.Adjacent
                            .Min(t => t.Item1.Distances[start.Id] + t.Item2);
                    }

                    foreach (var t in vertex.Adjacent)
                    {
                        if (t.Item1.Distances[start.Id] > vertex.Distances[start.Id] + t.Item2)
                        {
                            queue.Enqueue(t.Item1);
                        }
                    }
                }
            }

            return vertices;
        }

    }

    public class Car
    {
        private int destVId = 0;

        private int headingVId = 0;

        private int headingVDist = 0;

        public bool Arrived => destVId == headingVId && headingVDist == 0;

        public bool Returned => Arrived && destVId == 0;

        public void Return()
        {
            destVId = 0;
        }

        public void SetDest(int dest)
        {
            destVId = dest;
        }

        public string Drive(List<Vertex> graph)
        {
            if (Arrived) return "-1";

            if (headingVDist == 0)
            {
                headingVDist = int.MaxValue;

                Tuple<Vertex, int> next = graph[headingVId].Adjacent[0];
                foreach (var t in graph[headingVId].Adjacent)
                {
                    if (t.Item1.Distances[destVId] < next.Item2)
                    {
                        next = t;
                    }
                }
                headingVId = next.Item1.Id;
                headingVDist = next.Item2 - 1;
            }
            else
                headingVDist--;

            return (headingVId + 1).ToString();
        }
    }

    public class Vertex
    {
        public readonly int Id;
        public readonly List<Tuple<Vertex, int>> Adjacent;

        // TODO ushort
        public readonly int[] Distances;

        public Vertex(int id, int[] d)
        {
            this.Id = id;
            this.Adjacent = new List<Tuple<Vertex, int>>();
            this.Distances = d;
        }
    }

    #region "入出力"

    ///<summary>辺の入力。</summary>
    public class Side
    {
        public readonly int u;
        public readonly int v;
        public readonly int distance;

        public Side()
        {
            var ary = Console.ReadLine().Split();
            u = int.Parse(ary[0]) - 1;
            v = int.Parse(ary[1]) - 1;
            distance = int.Parse(ary[2]);
        }
    }

    public class FirstInput
    {
        public readonly int sizeV;
        private readonly int sizeE;
        ///<summary>辺の集合。</summary>
        public readonly List<Side> sides;
        ///<summary>注文頻度。</summary>
        public readonly List<int> freqs;
        public readonly int Tmax;

        public FirstInput()
        {
            var ary = Console.ReadLine().Split();
            sizeV = int.Parse(ary[0]);
            sizeE = int.Parse(ary[1]);

            sides = EnumerablePlus.Repeat(sizeE, () => new Side()).ToList();
            freqs = Console.ReadLine().Split().Select(int.Parse).ToList();
            Tmax = int.Parse(Console.ReadLine());
        }
    }

    public class Order
    {
        ///<summary>注文ID。</summary>
        public readonly int id;
        ///<summary>届け先頂点。</summary>
        public readonly int dst;

        public Order()
        {
            var ary = Console.ReadLine().Split();
            id = int.Parse(ary[0]);
            dst = int.Parse(ary[1]) - 1;
        }
    }

    public class OrdersInput
    {
        // TODO 0 or 1
        private readonly int sizeNew;
        ///<summary>新規注文。</summary>
        public readonly Order order;
        private readonly int sizePut;
        ///<summary>出荷開始注文。</summary>
        public readonly List<int> puts;

        public OrdersInput()
        {
            sizeNew = int.Parse(Console.ReadLine());
            if (sizeNew == 1)
                order = new Order();
            else
                order = null;
            sizePut = int.Parse(Console.ReadLine());
            puts = EnumerablePlus.Repeat(sizePut, () => int.Parse(Console.ReadLine())).ToList();
        }
    }

    public class VerdictInput
    {
        public readonly string verdict;
        private readonly int sizeArchive = 0;
        public readonly List<int> archives = null;

        public VerdictInput()
        {
            verdict = Console.ReadLine();

            if (verdict != "OK") return;

            sizeArchive = int.Parse(Console.ReadLine());
            archives = EnumerablePlus.Repeat(sizeArchive, () => int.Parse(Console.ReadLine())).ToList();
        }
    }

    #endregion

    public static class EnumerablePlus
    {
        ///<summary>出力文字列に変換。</summary>
        public static string MkString<T>(this IEnumerable<T> list)
        {
            return list.Aggregate(
                new System.Text.StringBuilder(),
                (a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b)
                ).ToString();
        }

        ///<summary>添字付きfor。</summary>
        public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a)
        {
            int i = 0;
            foreach (var item in list)
            {
                a(item, i);
            }
        }

        ///<summary>添字付きfor。</summary>
        public static void ForEach<T>(this IEnumerable<T> list, Action<T> a)
        {
            foreach (var item in list)
            {
                a(item);
            }
        }

        ///<summary>指定回数デリゲートを呼び出す。</summary>
        public static IEnumerable<T> Repeat<T>(int n, Func<T> f)
        {
            for (int i = 0; i < n; i++)
            {
                yield return f();
            }
        }
    }
}


Measured memory_bytes: 38280