#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, 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;
    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(i,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 tmax, next_cmd_id = 0, car_location = 1;
    map<int, int> orders; // id -> dest
    map<int, Cmd> cmds; // cmd_id -> Cmd
    cin >> tmax;
    FORi(t,0,tmax){
        bool new_order_appeared;
        cin >> new_order_appeared;
        if (new_order_appeared){
            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(i,0,orders_in_car_cnt){
            int id;
            cin >> id;
            int dst = orders[id];
            cmds[next_cmd_id] = {next_cmd_id++, dst};
        }

        if (cmds.empty() && car_location != 1){
            cmds[next_cmd_id] = {next_cmd_id++, 1};
        }
        int move = -1;
//        if (!cmds.empty()){
//            Cmd cmd = cmds.begin()->second;
//            cmds.erase(cmds.begin());
//            move = next[car_location][cmd.target_dst];
//            if (cmd.time_to_next_dst == -1){
//                cmd.time_to_next_dst = d[car_location][cmd.target_dst];
//            }
////            cout << car_location << " -> " << move << "[" << cmd.time_to_next_dst << "] => " << cmd.target_dst << " | ";
//            if (--cmd.time_to_next_dst){
//                cmds[cmd.id] = cmd;
//            }
//            else {
//                if (move != cmd.target_dst){
//                    cmd.time_to_next_dst = -1;
//                    cmds[cmd.id] = cmd;
//                }
//                car_location = move;
//            }
//            // todo: skip already delievered orders
//        }
        cout << move << endl;

        string verdict;
        cin >> verdict;
        if (verdict != "OK"){
            return 0;
        }
        int delievered_orders_cnt;
        cin >> delievered_orders_cnt;
        FORi(i,0,delievered_orders_cnt){
            int _stub;
            cin >> _stub;
        }
    }

    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: 1876