#include<bits/stdc++.h>

using namespace std;

constexpr int inf=1e8;

struct pos{
    int u,v;
    int d_u,d_v;
};

int main(){
    // input graph
    int n,m;
    cin>>n>>m;
    vector<vector<int>>dist(n+1,vector<int>(n+1,inf));
    vector<vector<int>>g(n+1);
    for(int i=0;i<m;++i){
        int u,v;
        cin>>u>>v;
        cin>>dist[u][v];
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int>f(n);
    for(int i=0;i<n;++i){
        cin>>f[i];
    }
    int T_max;
    cin>>T_max;

    //warshall-floyd
    for(int k=1;k<=n;++k){
        for(int i=1;i<=n;++i){
            for(int j=1;j<=n;++j){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }

    int target=1;
    double E_shop=0;
    vector<int>potential(n+1);
    vector<int>order(T_max);
    vector<bool>order_list(T_max);
    auto new_target = [&](pos now){
        int ret=1,d_min=inf;
        for(int j=0;j<T_max;++j){
            if(order_list[j]){
                if(d_min<min(dist[order[j]][now.u]+now.d_u,dist[order[j]][now.v]+now.d_v)){
                    d_min=min(dist[order[j]][now.u]+now.d_u,dist[order[j]][now.v]+now.d_v);
                    ret=order[j];
                }
            }
        }
        potential=dist[ret];
        return ret;
    };
    pos now;
    now.u=now.v=1;
    now.d_u=now.d_v=0;
    for(int i=0;i<T_max;++i){
        int n_order;
        cin>>n_order;
        for(int j=0;j<n_order;++j){
            int id,dst;
            cin>>id>>dst;
            order[id]=dst;
        }
        // shop-enelgy の更新
        // E_shop
        // to do
        int n_put;
        cin>>n_put;
        if(n_put){
            E_shop=0;
            for(int j=0;j<n_put;++j){
                int put_id;
                cin>>put_id;
                order_list[put_id]=true;
            }
            // target の更新
            target=new_target(now);
            //
        }

        cout<<-1<<endl;
        // 行動決め(本質)
        /*
        if(target==-1){
            cout<<-1<<endl;
        }else{
            int ret=-1;
            // 頂点上にいる場合
            if(now.u==now.v){
                int min_potential=potential[now.u];
                for(auto dst:g[now.u]){
                    if(min_potential<potential[dst]){
                        ret=dst;
                    }
                }
            }
            // 辺上にいる場合
            else{
                if(potential[now.u]+now.d_u<potential[now.v]+now.d_v){
                    ret=now.u;
                }else{
                    ret=now.v;
                }
            }
            cout<<ret<<endl;

            // 現在位置の更新
            if(ret!=-1){
                // 頂点上にいる場合
                if(now.u==now.v){
                    now.v=ret;
                    now.d_u=1;
                    now.d_v=dist[now.u][now.v]-now.d_u;
                }
                // 辺上にいる場合
                else{
                    if(ret==now.u){
                        now.d_u--;
                        now.d_v++;
                        if(now.d_u==0){
                            now.v=now.u;
                            now.d_v=0;
                        }
                    }
                    if(ret==now.v){
                        now.d_u++;
                        now.d_v--;
                        if(now.d_v==0){
                            now.u=now.v;
                            now.d_u=0;
                        }
                    }
                }
            }
        }
        */
        //
        // to do

        string judge;
        cin>>judge;
        if(judge=="NG")return 0;
        int n_achieve;
        cin>>n_achieve;
        for(int j=0;j<n_achieve;++j){
            int achieve_id;
            cin>>achieve_id;
            if(order_list[achieve_id]){
                order_list[achieve_id]=false;
                // target の更新
                target=new_target(now); 
                //
            }
        }
    }
}

Measured memory_bytes: 2128