import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.SplittableRandom;

public class Main {
    private static final long startTime = System.currentTimeMillis();
    private static final boolean LOCAL = false;
    private static final boolean DEBUG = false;
    private static final long TL = LOCAL ? 10000 : 29000;
    private static final int INF = 1 << 29;
    private static final int TMAX = 10000;
    private static final long TMAX2 = TMAX * TMAX;
    private static final int TLAST = 9500;
    private static final Scanner sc = new Scanner(System.in);
    private static final SplittableRandom rnd = new SplittableRandom(42);
    private static int V, E;
    private static int[][] G, G_PREV;
    private static int[] freq;
    private static int[] orders = new int[TMAX];
    private static int[] orderCount = new int[TMAX + 1];
    private static int lastOrder;
    private static IntAry[] vos;
    private static int DIST_ALLOW = 15;
    private static int RETURN_TO_SHOP_TH = 20;
    private static int[] nextDeliver;
    private static Plan plan = new Plan();
    private static Pos pos = new Pos();
    private static long score;

    public static void main(String[] args) {
        V = sc.nextInt();
        E = sc.nextInt();
        freq = new int[V];
        G = new int[V][V];
        G_PREV = new int[V][V];
        vos = new IntAry[V];
        nextDeliver = new int[V];
        plan.ary = new IntAry();
        for (int i = 0; i < V; i++) {
            Arrays.fill(G[i], INF);
            vos[i] = new IntAry(TMAX * 2 / V);
            G[i][i] = 0;
            G_PREV[i][i] = i;
        }
        for (int i = 0; i < E; i++) {
            int u = Integer.parseInt(sc.next()) - 1;
            int v = Integer.parseInt(sc.next()) - 1;
            int d = Integer.parseInt(sc.next());
            G[u][v] = G[v][u] = d;
            G_PREV[u][v] = u;
            G_PREV[v][u] = v;
        }
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                for (int k = 0; k < V; k++) {
                    if (G[j][k] > G[j][i] + G[i][k]) {
                        G[j][k] = G[j][i] + G[i][k];
                        G_PREV[j][k] = i;
                    }
                }
            }
        }
        for (int i = 0; i < V; i++) {
            freq[i] = sc.nextInt();
        }
        sc.next();
        for (int i = 0; i < TMAX; i++) {
            if (i > 0) orderCount[i] = orderCount[i - 1];
            if (sc.next().charAt(0) == '1') {
                sc.next();
                int dst = sc.nextInt() - 1;
                orders[i] = dst;
                vos[dst].add(i);
                lastOrder = i;
                orderCount[i]++;
            }
            int put = sc.nextInt();
            for (int j = 0; j < put; j++) {
                sc.next();
            }
            int command = solveSinglePeriod(i);
            System.out.println(command == -1 ? command : command + 1);
            sc.next(); // verdict
            int deliv = sc.nextInt();
            for (int j = 0; j < deliv; j++) {
                sc.next();
            }
        }
        if (DEBUG) {
            int orderCount = 0;
            int undeliver = 0;
            for (int i = 0; i < TLAST; i++) {
                if (orders[i] != 0) orderCount++;
            }
            for (int i = 0; i < V; i++) {
                undeliver += vos[i].size - nextDeliver[i];
            }
            debugfln("score:%d undeliver:%d/%d", score, undeliver, orderCount);
        }
    }

    static int solveSinglePeriod(int time) {
        int dist = G[pos.from][pos.to];
        if (dist == pos.move) {
            while (nextDeliver[pos.to] < vos[pos.to].size && vos[pos.to].a[nextDeliver[pos.to]] <= plan.startAt) {
                score += TMAX2 - sq(time - vos[pos.to].a[nextDeliver[pos.to]]);
                nextDeliver[pos.to]++;
            }
            if (plan.full()) {
                plan = createPlan(time);
            }
            if (plan.size() == 0) {
                pos.from = pos.to = pos.move = 0;
                return -1;
            }
            pos.from = pos.to;
            pos.to = plan.next();
            if (pos.from != 0 && orderCount[time] - orderCount[plan.startAt] > RETURN_TO_SHOP_TH && G[pos.from][0] + G[0][pos.to] < G[pos.from][pos.to] + DIST_ALLOW) {
                plan.setShop(pos.from);
                pos.to = plan.next();
            }
            pos.move = 1;
        } else {
            pos.move++;
        }
        debugfln("%d %d->%d %d", time, pos.from, pos.to, pos.move);
        return pos.to;
    }

    private static long[] countO = new long[400];
    private static long[] coefO = new long[400];
    private static long[] constO = new long[400];

    static Plan createPlan(int startAt) {
        IntAry vs = new IntAry();
        for (int i = 1; i < V; i++) {
            if (nextDeliver[i] < vos[i].size && vos[i].a[nextDeliver[i]] <= startAt) {
                vs.add(i);
                int j = nextDeliver[i];
                countO[i] = coefO[i] = constO[i] = 0;
                while (j < vos[i].size && vos[i].a[j] <= startAt) {
                    countO[i]++;
                    coefO[i] += 2 * vos[i].a[j];
                    constO[i] += vos[i].a[j] * vos[i].a[j];
                    j++;
                }
            }
        }
        plan.startAt = startAt;
        if (vs.size == 0) {
            // wait
            plan.set(new IntAry());
            return plan;
        }
        long score = 0;
        long t = startAt;

        for (int i = 0; i < vs.size - 1; i++) {
            int pos = rnd.nextInt(vs.size - i) + i;
            swap(vs.a, i, pos);
        }
        for (int i = 0, cur = 0; i < vs.size; i++) {
            long min = Long.MAX_VALUE;
            int mi = -1;
            for (int j = i; j < vs.size; j++) {
                long ev = G[cur][vs.a[j]];
                if (ev < min) {
                    min = ev;
                    mi = j;
                }
            }
            swap(vs.a, i, mi);
            cur = vs.a[i];
            t += min;
            if (t <= TMAX) {
                score += countO[cur] * (TMAX2 - t * t) + coefO[cur] * t - constO[cur];
            }
        }

        int maxCount = vs.size <= 5 ? vs.size - 1 : vs.size <= 10 ? (vs.size - 1) * 7 : (vs.size - 1) * 400;
        for (int i = 0; i < maxCount; i++) {
            if ((i & 0xF) == 0) {
                long elapsed = System.currentTimeMillis() - startTime;
                if (TL * startAt < elapsed * TMAX) {
                    debugfln("turn:%d", i);
                    break;
                }
            }
            int ml = INF;
            int p1 = rnd.nextInt(vs.size);
            int pn1 = p1 == 0 ? 0 : vs.a[p1 - 1];
            int nn1 = p1 == vs.size - 1 ? 0 : vs.a[p1 + 1];
            int p2 = -1;
            for (int j = 0; j <= p1 - 1; j++) {
                int pn2 = j == 0 ? 0 : vs.a[j - 1];
                int diff = G[pn2][vs.a[p1]] + G[nn1][vs.a[j]] - G[pn2][vs.a[j]] - G[nn1][vs.a[p1]];
                if (diff < ml || diff == ml && (rnd.nextInt() & 1) == 0) {
                    ml = diff;
                    p2 = j;
                }
            }
            for (int j = p1 + 1; j < vs.size; j++) {
                int nn2 = j == vs.size - 1 ? 0 : vs.a[j + 1];
                int diff = G[pn1][vs.a[j]] + G[vs.a[p1]][nn2] - G[pn1][vs.a[p1]] - G[vs.a[j]][nn2];
                if (diff < ml || diff == ml && (rnd.nextInt() & 1) == 0) {
                    ml = diff;
                    p2 = j;
                }
            }
            if (p2 < p1) {
                int tmp = p2;
                p2 = p1;
                p1 = tmp;
            }
            // 2-opt
            t = startAt;
            long nextScore = 0;
            int pp = 0;
            for (int j = 0; j < p1 && t <= TMAX; j++) {
                int cur = vs.a[j];
                t += G[pp][cur];
                if (t > TMAX) break;
                nextScore += countO[cur] * (TMAX2 - t * t) + coefO[cur] * t - constO[cur];
                pp = cur;
            }
            for (int j = p2; j >= p1 && t <= TMAX; j--) {
                int cur = vs.a[j];
                t += G[pp][cur];
                if (t > TMAX) break;
                nextScore += countO[cur] * (TMAX2 - t * t) + coefO[cur] * t - constO[cur];
                pp = cur;
            }
            for (int j = p2 + 1; j < vs.size && t <= TMAX; j++) {
                int cur = vs.a[j];
                t += G[pp][cur];
                if (t > TMAX) break;
                nextScore += countO[cur] * (TMAX2 - t * t) + coefO[cur] * t - constO[cur];
                pp = cur;
            }
            if (score < nextScore) {
                for (int lo = p1, hi = p2; lo < hi; lo++, hi--) {
                    swap(vs.a, lo, hi);
                }
                debugfln("score:%d->%d at %d", score, nextScore, i);
                score = nextScore;
            }
        }
        plan.set(vs);
        return plan;
    }

    static class Plan {
        IntAry ary;
        int pos, startAt;

        int size() {
            return ary.size;
        }

        int next() {
            return ary.a[pos++];
        }

        boolean full() {
            return pos == ary.size;
        }

        void set(IntAry path) {
            pos = 0;
            ary.clear();
            if (path.size == 0) return;
            int prev = 0;
            for (int i = 0; i < path.size; i++) {
                setRec(prev, path.a[i]);
                prev = path.a[i];
            }
            setRec(prev, 0);
        }

        void setShop(int here) {
            pos = 0;
            ary.clear();
            setRec(here, 0);
        }

        void setRec(int u, int v) {
            if (G_PREV[u][v] == u) {
                ary.add(v);
            } else {
                setRec(u, G_PREV[u][v]);
                setRec(G_PREV[u][v], v);
            }
        }
    }

    static class Pos {
        int from, to, move;
    }


    static final class IntAry {
        int[] a;
        int size;

        IntAry() {
            a = new int[16];
        }

        IntAry(int cap) {
            a = new int[cap];
        }

        IntAry(int[] a) {
            this.a = a;
            this.size = a.length;
        }

        IntAry(IntAry that) {
            a = that.a.clone();
            size = that.size;
        }

        @Override
        public String toString() {
            return Arrays.toString(Arrays.copyOf(a, size));
        }

        IntAry copyOf(int from, int to) {
            return new IntAry(Arrays.copyOfRange(this.a, from, to));
        }

        void add(int v) {
            if (size == a.length) {
                int[] na = new int[a.length * 2];
                System.arraycopy(a, 0, na, 0, size);
                a = na;
            }
            a[size++] = v;
        }

        void addAll(IntAry ia) {
            if (this.size + ia.size < a.length) {
                int[] na = new int[this.size + ia.size];
                System.arraycopy(a, 0, na, 0, size);
                a = na;
            }
            System.arraycopy(ia.a, 0, a, size, ia.size);
            size += ia.size;
        }

        void clear() {
            size = 0;
        }

        int pop() {
            size--;
            return a[size];
        }

        int back() {
            return a[size - 1];
        }

        void remove(int pos) {
            System.arraycopy(a, pos + 1, a, pos, size - pos - 1);
            size--;
        }

        void swapRemove(int pos) {
            swap(a, pos, size - 1);
            size--;
        }

        void sort() {
            Arrays.sort(a, 0, size);
        }

        void reverse() {
            for (int lo = 0, hi = size - 1; lo < hi; lo++, hi--) {
                swap(a, lo, hi);
            }
        }
    }

    private static void swap(int[] a, int p1, int p2) {
        int tmp = a[p1];
        a[p1] = a[p2];
        a[p2] = tmp;
    }

    private static long sq(long v) {
        return v * v;
    }

    private static void debug(String str) {
        if (DEBUG) System.err.println(str);
    }

    private static void debug(Object... obj) {
        if (DEBUG) System.err.println(Arrays.deepToString(obj));
    }

    private static void debugfln(String fmt, Object... obj) {
        if (DEBUG) System.err.printf(fmt + "\n", obj);
    }

    private static final class Counter {
        ArrayList<Integer> count = new ArrayList<>();

        void add(int i) {
            if (DEBUG) {
                while (count.size() <= i) {
                    count.add(0);
                }
                count.set(i, count.get(i) + 1);
            }
        }

        void print() {
            if (DEBUG) {
                System.err.print("[");
                for (int i = 0; i < count.size(); ++i) {
                    System.err.print(count.get(i) + ", ");
                }
                System.err.println("]");
            }
        }
    }
}


Measured memory_bytes: 55580