#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define LL long long int
#define ULL unsigned LL
#define LD long double
#define PB push_back
#define PF push_front
#define MP make_pair
#define FORi(i, a, b) for(int i = a; i < b ; ++i)
#define FORd(i, a, b) for(int i = a; i > b ; --i)

using namespace std;

struct Cmd {
    int id, target_dst, order_id=0, time_to_next_dst=-1;

    bool operator < (const Cmd & other) const {
        return id < other.id;
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

    /* Init */
    const int N = 401;
    const int INF = 1e9;
    const string OK = "OK";
    const string NG = "NG";
    int n,m;
    cin >> n >> m;
    int d[N][N], next[N][N];
    FORi(i, 1, N) {
        FORi(j, 1, N) {
            d[i][j] = INF;
            next[i][j] = j;
        }
        d[i][i] = 0;
    }
    /* Input */
    FORi(i,0,m){
        int u,v,w;
        cin >> u >> v >> w;
        d[u][v] = d[v][u] = w;
    }
    FORi(_,0,n){
        int _stub;
        cin >> _stub;
    }
    /* Precalc */
    FORi(i, 1, N) {
        FORi(u, 1, N) {
            FORi(v, 1, N) {
                if (d[u][i] + d[i][v] < d[u][v]) {
                    d[u][v] = d[u][i] + d[i][v];
                    next[u][v] = next[u][i];
                }
            }
        }
    }

//    FORi(u, 1, n+1) {
//        FORi(v, 1, n+1) {
//            cout << d[u][v] << " " << next[u][v] << endl;
//        }
//    }
    /* Processing */
    int t_max, next_cmd_id = 0, car_location = 1;
    string verdict;
    map<int, int> orders; // id -> destination
    map<int, Cmd> cmds; // cmd_id -> Cmd
    cin >> t_max;
    FORi(t,0,t_max){
        int new_orders;
        cin >> new_orders;
        FORi(_,0,new_orders){
            int id, dst;
            cin >> id >> dst;
            orders[id] = dst;
            // todo: memorize time in order to choose orders wisely
        }

        int orders_in_car_cnt;
        cin >> orders_in_car_cnt;
        FORi(_,0,orders_in_car_cnt){
            int id;
            cin >> id;
            int dst = orders[id];
            cmds[next_cmd_id] = {next_cmd_id, dst, id};
            next_cmd_id++;
        }

//        cout << cmds.size() << ' ' << car_location << endl;

        if (cmds.empty() && car_location != 1){
            cmds[next_cmd_id] = {next_cmd_id, 1};
            next_cmd_id++;
        }
        int move = -1;
        if (!cmds.empty()){
            Cmd cmd = cmds.begin()->second;
            move = next[car_location][cmd.target_dst];
        }
        cout << move << endl;

        cin >> verdict;
        if (verdict == NG){
            return 0;
        }
//        cout << verdict << ' ' << move;
        if (verdict == OK && move != -1){
            Cmd cmd = cmds.begin()->second;
            if (cmd.time_to_next_dst == -1){
                cmd.time_to_next_dst = d[car_location][move];
            }
            --cmd.time_to_next_dst;
            cmds.erase(cmds.begin());
            cmds[cmd.id] = cmd;
//            cout << car_location << " -> " << move << "[" << cmd.time_to_next_dst << "] => " << cmd.target_dst << " | ";
            if (cmd.time_to_next_dst == 0){
                car_location = move;
                cmds.erase(cmds.begin());
                if (car_location != cmd.target_dst){
                    cmd.time_to_next_dst = -1;
                    cmds[cmd.id] = cmd;
                }
            }
        }
//        cout << endl;
        int delievered_orders_cnt;
        cin >> delievered_orders_cnt;
        FORi(_,0,delievered_orders_cnt){
            int id;
            cin >> id;
            for(auto cmd: cmds){
                if (cmd.second.order_id == id){
                    cmds.erase(cmd.first);
                    break;
                }
            }
        }
    }

    return 0;
}

/*
5 7
1 2 5
5 3 4
2 4 8
1 5 1
2 3 3
4 5 3
4 3 9
0 1 1 5 5
500
1
1 5
1
1

OK
1
1
1
2 2
0

OK
0
1
3 4
2
2 3

OK
0
0
0

 */

Measured memory_bytes: 3152