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

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

struct STATE {
    ll score;
    int tour_size;
    pair<int,int> tours[Tmax];
    int orders[400];
    int stocks_size;
    int stocks[Tmax];

    STATE() {
        score = 0;
        stocks_size = 0;
        tour_size = 0;
        memset(orders, 0, sizeof(orders));
    }
};

void init() {
    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 >> _;
}

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) {
    vector<int> points;
    for (int i = 0; i < V; i++) {
        if (state.orders[i]) {
            points.push_back(i);
        }
    }
    points.push_back(0);
    sort(points.begin(), points.end());
    points.erase(unique(points.begin(), points.end()), 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 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);
    memset(state.orders, 0, sizeof(state.orders));
}

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];
        int Nput;
        cin >> Nput;
        for (int j = 0; j < Nput; j++) cin >> trash;
        if (ORDER[i] != -1) {
            now_state.orders[ORDER[i]]++;
            now_state.stocks[now_state.stocks_size++];
        }
        if (!now_state.tour_size) {
            tsp(now_state);
        }
        if (now_state.tour_size) {
            cout << now_state.tours[now_state.tour_size-1].first+1 << endl;
            now_state.tours[now_state.tour_size-1].second--;
            if (!now_state.tours[now_state.tour_size-1].second) {
                now_state.tour_size--;
            }
        } 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: 2000