#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];

int back_time = 0;

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

    STATE() {
        score = 0;
        tour_size = 0;
        pos = 0;
        orders_sum = 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;
        orders_sum = st.orders_sum;
        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]);
            }
        }
    }
}

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 >> _;
}

void optimize_path(vector<int>& path) {
    if (path.size() <= 3) return;
    int n = path.size();
    unsigned long long int start_cycle = getCycle();

    double TIME_LIMIT = 0.1;

    double now_t = 0.0;

    double last_up = 0.0;

    for (int loop = 0;; loop++) {
        if (loop%1000 == 0) {
            now_t = getTime(start_cycle);
            if (now_t > TIME_LIMIT) break;
        }

        if (engine.rand()%2) {
            int i = engine.rand()%n;
            int j = engine.rand()%n;
            if (i >= j) swap(i,j);
            if (j-i <= 1 || j-i == 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 (new_dist <= ori_dist) {
                last_up = now_t;
                int swap_st = i+1, swap_en = j;
                while (swap_st < swap_en) {
                    swap(path[swap_st], path[swap_en]);
                    swap_st++;
                    swap_en--;
                }
            }
        } else {
            int i = engine.rand()%(n-1)+1;
            int j = engine.rand()%n;
            if (i == j || i-1 == j) continue;

            int i2 = (i+1)%n;
            int j2 = (j+1)%n;
            int ori_dist = DIST[path[i-1]][path[i]] + DIST[path[i]][path[i2]] + DIST[path[j]][path[j2]];
            int new_dist = DIST[path[i-1]][path[i2]] + DIST[path[j]][path[i]] + DIST[path[i]][path[j2]];

            if (new_dist <= ori_dist) {
                if (i > j) {
                    int tmp = path[i];
                    for (int k = i-1; k > j; k--) path[k+1] = path[k];
                    path[j+1] = tmp;
                } else {
                    int tmp = path[i];
                    for (int k = i+1; k <= j; k++) path[k-1] = path[k];
                    path[j] = tmp;
                }
            }
        }
    }
}

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];
        }
    }

    // do reverse

    for (int i = 0; i < (int)path.size()-2; i++) {
        if (DIST[path[i]][0]+DIST[0][path[i+1]]-DIST[path[i]][path[i+1]] < 5) {
            path[i+1] = 0;
            path.erase(path.begin()+i+2, path.end());
        }
    }

    for (int i = 1; i < (int)path.size()-2; i++) {
        if (DIST[path[i]][path[i+1]] == DIST[path[i]][0]+DIST[path[i+1]][0]) {
            cerr << "Hoge" << endl;
        }
    }

    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 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_sum++;
            now_state.orders[ORDER[i]][now_state.orders_si[ORDER[i]]++] = i;
        }

        if (now_state.pos == 0) {
            now_state.orders_sum = 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;
            }
            now_state.tour_size = 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--;
                now_state.pos = to;
                /*
                if (to != 0 && DIST[to][0] < now_state.orders_sum/200) {
                    int now_pos = to;
                    now_state.tour_size = 0;
                    while (now_pos != 0) {
                        for (pair<int,int> e : EDGE[now_pos]) {
                            if (DIST[now_pos][0] == e.second + DIST[e.first][0]) {
                                now_state.tours[now_state.tour_size++] = pair<int,int>(e.first, e.second);
                                now_pos = e.first;
                                break;
                            }
                        }
                    }
                    reverse(now_state.tours, now_state.tours+now_state.tour_size);
                }
                */
            } 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;
        }
    }
    cerr << now_state.score << endl;
    cerr << endl;
}

int main() {
    input();

    init();

    solve();

    return 0;
}

Measured memory_bytes: 2640