#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <random>
#include <string.h>
#define inf 100000000
using namespace std;
typedef long long int ll;

const unsigned long long int cycle_per_sec = 2800000000;

unsigned long long int getCycle() {
    unsigned int low, high;
    __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
    return ((unsigned long long int)low) | ((unsigned long long int)high << 32);
}

double getTime (unsigned long long int begin_cycle) {
    return (double)(getCycle() - begin_cycle) / cycle_per_sec;
}

class XorShift {
public:
    unsigned int x;
    unsigned int y;
    unsigned int z;
    unsigned int w;
    unsigned int t;
    
    XorShift(int tmp) {
        mt19937 rnd(tmp);
        x = rnd();
        y = rnd();
        z = rnd();
        w = rnd();
        t = 1;
    }
    
    int rand() {
        t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
        return w & 0x7fffffff;
    }
} engine(rand());

const int PEAK_UPDATE_SPAN = 100;

int V, E;
vector<pair<int,int>> EDGE[400];
int DIST[400][400];
const int Tmax = 10000;
int F[400];
int ORDER[Tmax];
int PEAK;
int ORDER_FREQ[PEAK_UPDATE_SPAN];

struct STATE {
    ll score;
    int tour_size;
    pair<int,int> tours[Tmax];
    int orders_si[400];
    int orders[400][100];
    int havings_si[400];
    int havings[400][100];
    int pos; // -1 if on edge

    STATE() {
        score = 0;
        tour_size = 0;
        pos = 0;
        memset(orders_si, 0, sizeof(orders_si));
        memset(havings_si, 0, sizeof(havings_si));
    }

    void copy (STATE& st) {
        score = st.score;
        tour_size = st.tour_size;
        pos = st.pos;
        for (int i = 0; i < V; i++) {
            orders_si[i] = st.orders_si[i];
            for (int j = 0; j < orders_si[i]; j++) {
                orders[i][j] = st.orders[i][j];
            }
            havings_si[i] = st.havings_si[i];
            for (int j = 0; j < havings_si[i]; j++) {
                havings[i][j] = st.havings[i][j];
            }
        }
    }
};

void init() {
    PEAK = 4750;
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            DIST[i][j] = inf;
        }
        DIST[i][i] = 0;
    }
    for (int i = 0; i < V; i++) {
        for (pair<int, int>& e: EDGE[i]) {
            DIST[i][e.first] = min(DIST[i][e.first], e.second);
        }
    }
    for (int u = 0; u < V; u++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                DIST[i][j] = min(DIST[i][j], DIST[i][u] + DIST[u][j]);
            }
        }
    }
    int maxDist = 0;
    for (int i = 0; i < V; i++) {
        maxDist = max(maxDist, *max_element(DIST[i], DIST[i]+V));
    }
}

void input() {
    cin >> V >> E;
    for(int i = 0; i < E; i++) {
        // recieve edges
        int u, v, d; std::cin >> u >> v >> d;
        u--; v--;
        EDGE[u].push_back({v, d});
        EDGE[v].push_back({u, d});
    }
    for (int i = 0; i < V; i++) {
        cin >> F[i];
    }
    int _;
    cin >> _;
}

ll last_tsp(STATE& state, int now, int limit) {
    ll ret = 0;

    limit = limit-now;
    vector<int> points;
    for (int i = 0; i < V; i++) {
        if (state.havings_si[i]) {
            points.push_back(i);
        }
    }
    points.push_back(0);
    sort(points.begin(), points.end());

    vector<bool> saw((int)points.size(), false);
    int pre = 0;
    saw[pre] = true;
    for (int i = 0; i < (int)points.size()-1; i++) {
        int dis = inf;
        int to = -1;
        for (int j = 0; j < (int)points.size(); j++) {
            if (saw[j]) continue;
            if (dis > DIST[points[pre]][points[j]]) {
                dis = DIST[points[pre]][points[j]];
                to = j;
            }
        }
        limit -= dis;
        if (limit < 0) {
            return ret;
        }

        now += DIST[points[pre]][points[to]];
        for (int j = 0; j < state.havings_si[points[to]]; j++) {
            ll dif = now+1-state.havings[points[to]][j];
            ret += Tmax*Tmax-dif*dif;
        }

        pre = to;
        saw[to] = true;
    }
    return ret;
}

/*
ll calc_tour_score (STATE& state, vector<int>& path, int now) {
    int now_pos = 0;
    ll ret = 0;
    for (int i = 0; i < (int)path.size(); i++) {
        now += DIST[now_pos][path[i]];
        for (int j = 0; j < state.havings_si[path[i]]; j++) {
            ll dif = now+1-state.havings[path[i]][j];
            ret += Tmax*Tmax-dif*dif;
        }
        now_pos = path[i];
    }
    return ret;
}
*/

// score, len
pair<ll,int> cancel_path (STATE& origin_state, vector<int>& path, int now, int limit) {
    STATE state;
    state.copy(origin_state);
    state.pos = 0;

    int now_pos = 0;
    ll best_score = 0;
    ll sum = 0;
    int best_len = path.size()-1;
    for (int i = 0; i < (int)path.size()-1; i++) {
        for (int t = 0; t < DIST[now_pos][path[i]]; t++) {
            if (ORDER[now+t] != -1) {
                state.orders[ORDER[now+t]][state.orders_si[ORDER[now+t]]++] = now+t;
            }
        }
        now += DIST[now_pos][path[i]];
        now_pos = path[i];
        for (int j = 0; j < state.havings_si[now_pos]; j++) {
            ll dif = now+1-state.havings[now_pos][j];
            sum += Tmax*Tmax-dif*dif;
        }
        state.havings_si[now_pos] = 0;

        if (DIST[now_pos][0] > 10) continue;

        STATE new_state;
        new_state.copy(state);
        int zero_t = now+DIST[now_pos][0];
        for (int t = 0; t < DIST[now_pos][0]; t++) {
            if (ORDER[now+t] != -1) {
                new_state.orders[ORDER[now+t]][new_state.orders_si[ORDER[now+t]]++] = now+t;
            }
        }
        for (int v = 0; v < V; v++) {
            for (int j = 0; j < new_state.orders_si[v]; j++) {
                new_state.havings[v][new_state.havings_si[v]++] = new_state.orders[v][j];
            }
        }

        ll now_score = sum + last_tsp(new_state, zero_t, limit);
        if (best_score < now_score) {
            best_score = now_score;
            best_len = i+1;
        }
    }
    return pair<ll,int>(best_score, best_len);
}

void optimize_path(vector<int>& path) {
    int n = path.size();
    while (true) {
        bool end = true;
        for (int i = 0; i < n; i++) {
            for (int j = i+2; j < n; j++) {
                if (i == 0 && j == n-1) continue;
                int j2 = (j+1)%n;
                int ori_dist = DIST[path[i]][path[i+1]] + DIST[path[j]][path[j2]];
                int new_dist = DIST[path[i]][path[j]] + DIST[path[i+1]][path[j2]];
                if (ori_dist > new_dist) {
                    end = false;
                    int swap_st = i+1, swap_en = j;
                    while (swap_st < swap_en) {
                        swap(path[swap_st], path[swap_en]);
                        swap_st++;
                        swap_en--;
                    }
                }
            }
        }
        if (end) break;
    }
}


void tsp(STATE& state, int now_t) {
    vector<int> points;
    for (int i = 0; i < V; i++) {
        if (state.havings_si[i]) {
            points.push_back(i);
        }
    }
    if (points.size() == 0) return;
    points.push_back(0);
    sort(points.begin(), points.end());

    vector<bool> saw((int)points.size(), false);
    vector<int> path((int)points.size());
    int pre = 0;
    path[0] = points[0];
    saw[pre] = true;
    for (int i = 0; i < (int)points.size()-1; i++) {
        int dis = inf;
        int to = -1;
        for (int j = 0; j < (int)points.size(); j++) {
            if (saw[j]) continue;
            if (dis > DIST[points[pre]][points[j]]) {
                dis = DIST[points[pre]][points[j]];
                to = j;
            }
        }
        pre = to;
        saw[to] = true;
        path[i+1] = points[to];
    }
    optimize_path(path);
    for (int i = 0; i < (int)path.size()-1; i++) {
        path[i] = path[i+1];
    }
    path[(int)path.size()-1] = points[0];

    int path_time = 0;
    {
        int now_pos = 0;
        for (int i = 0; i < (int)path.size()-1; i++) {
            path_time += DIST[now_pos][path[i]];
            now_pos = path[i];
        }
        /*
        if (now_t + path_time >= Tmax) {
            last_optimize_path(state, path);
        }
        */
    }

    pair<ll, int> best_path1, best_path2;
    best_path1 = cancel_path(state, path, now_t, now_t+path_time);
    //cerr << path.size() << endl;
    //cerr << best_path1.first << " " << best_path1.second << endl;
    reverse(path.begin(), path.end()-1);
    best_path2 = cancel_path(state, path, now_t, now_t+path_time);
    //cerr << best_path2.first << " " << best_path2.second << endl;
    //cerr << endl;

    if (best_path1.first > best_path2.first) {
        reverse(path.begin(), path.end()-1);
    } else {
        best_path1 = best_path2;
    }

    //state.score += best_path1.first;
    //cerr << state.score << endl;

    path[best_path1.second++] = points[0];

    int now_pos = points[0];
    for (int i = 0; i < best_path1.second; i++) {
        while (now_pos != path[i]) {
            for (pair<int,int> e : EDGE[now_pos]) {
                if (DIST[now_pos][path[i]] == e.second + DIST[e.first][path[i]]) {
                    state.tours[state.tour_size++] = pair<int,int>(e.first, e.second);
                    now_pos = e.first;
                    break;
                }
            }
        }
    }
    /*
    int now_pos = points[0];
    for (int i = 0; i < (int)path.size(); i++) {
        while (now_pos != path[i]) {
            for (pair<int,int> e : EDGE[now_pos]) {
                if (DIST[now_pos][path[i]] == e.second + DIST[e.first][path[i]]) {
                    state.tours[state.tour_size++] = pair<int,int>(e.first, e.second);
                    now_pos = e.first;
                    break;
                }
            }
        }
    }
    */
    reverse(state.tours, state.tours+state.tour_size);
}


void update_peak(int si) {
    int bestp = PEAK;
    double bestval = (double)inf;
    for (int p = 0; p < 9500; p += 100) {
        double val = 0.0;
        for (int i = 0; i < si; i++) {
            double ratio = ORDER_FREQ[i]/(double)PEAK_UPDATE_SPAN;
            int mid = i*PEAK_UPDATE_SPAN + PEAK_UPDATE_SPAN/2;
            double ex = (p>=mid)?(mid/(double)p):((9500-mid)/(double)(9500-p));
            val += (ratio-ex)*(ratio-ex);
        }
        if (val < bestval) {
            bestval = val;
            bestp = p;
        }
    }
    PEAK = bestp;
}

void update_future(int t) {
    int sum = 0;
    int hoge[800];
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < F[i]; j++) {
            hoge[sum++] = i;
        }
    }
    for (int i = t+1; i < Tmax; i++) {
        double order_prob = (PEAK>=i)?(i/(double)PEAK):((9500-i)/(double)(9500-PEAK));
        if ((engine.rand()%inf)/(double)inf < order_prob) {
            ORDER[i] = -1;
            continue;
        }
        ORDER[i] = hoge[engine.rand()%sum];
    }
}

void solve() {
    STATE now_state;
    for (int i = 0; i < Tmax; i++) {
        ORDER[i] = -1;
        int Nnew, trash;
        cin >> Nnew;
        if (Nnew == 1) {
            cin >> trash >> ORDER[i];
            ORDER[i]--;
        }
        int Nput;
        cin >> Nput;
        for (int j = 0; j < Nput; j++) cin >> trash;
        if (ORDER[i] != -1) {
            ORDER_FREQ[i*PEAK_UPDATE_SPAN/Tmax]++;
            now_state.orders[ORDER[i]][now_state.orders_si[ORDER[i]]++] = i;
        }
        if (i%PEAK_UPDATE_SPAN == PEAK_UPDATE_SPAN-1) {
            update_peak(i*PEAK_UPDATE_SPAN/Tmax+1);
            //update_future(i);
        }
        if (now_state.pos == 0) {
            for (int v = 0; v < V; v++) {
                for (int j = 0; j < now_state.orders_si[v]; j++) {
                    now_state.havings[v][now_state.havings_si[v]++] = now_state.orders[v][j];
                }
                now_state.orders_si[v] = 0;
            }
        }
        if (!now_state.tour_size) {
            tsp(now_state, i);
        }
        if (now_state.tour_size) {
            int to = now_state.tours[now_state.tour_size-1].first;
            cout << to+1 << endl;
            now_state.tours[now_state.tour_size-1].second--;
            if (!now_state.tours[now_state.tour_size-1].second) {
                for (int j = 0; j < now_state.havings_si[to]; j++) {
                    ll dif = i+1-now_state.havings[to][j];
                    now_state.score += Tmax*Tmax-dif*dif;
                }
                now_state.havings_si[to] = 0;
                now_state.tour_size--;
                /*
                if (now_state.tour_size == 0) {
                    cerr << now_state.score << endl;
                }
                */
                now_state.pos = to;
            } else {
                now_state.pos = -1;
            }
        } else {
            cout << -1 << endl;
        }
        string verdict; cin >> verdict;
        if (verdict == "NG") {
            exit(1);
        }

        // the number of orders that have been delivered at time t.
        int Nachive; cin >> Nachive;
        for(int j = 0; j < Nachive; j++) {
            int achive_id; cin >> achive_id;
        }
    }
}

int main() {
    input();

    init();

    solve();

    return 0;
}


Measured memory_bytes: 2772