#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int dist[410][410],to[410][410];
int tmax;

double WEIGHT=0.48;

class Order{
public:
    int dst,ot; //目的地と注文時刻 destination ordertime
    int status; //0:未発注 1:注文済 2:入荷済　3:発送済み

    Order(int x,int y){
        dst=y;
        ot=x;
        status=1;
    }

    Order(const Order& src){ //コピーコンストラクタ
        dst=src.dst;
        ot=src.ot;
        status=src.status;
    }


};

vector<Order> order;


void path(int s, int g,queue<int>& q){  //s,g間の最短経路を格納
    int pos;
    for (pos = s; pos!=g ; pos=to[pos][g]) {
        if(pos!=s) q.push(pos);
    }
    q.push(g);
    //q.pop();
}

int nodepos=0; //ノード上のときノード番号，それ以外の時-1
int kyori=0; //エッジ上の時その距離，それ以外0
int fromnode=-1,tonode=-1; //エッジ上の時の両端のノード
int x=0; //fromからの距離

void move(queue<int>& q){
    int node=q.front();
    if(node==nodepos){
        q.pop();
        cout<<-1<<endl;
        return;
    }
    cout<<node+1<<endl;
    if(nodepos==-1){ //辺上
        if(node==tonode){
            ++x;
            if(x==kyori){
                nodepos=node;
                kyori=0;
                fromnode=-1; tonode=-1;
                x=0;
                q.pop();
            }
        }else{
            --x;
            if(x==0){
                nodepos=node;
                kyori=0;
                fromnode=-1; tonode=-1;
                x=0;
                q.pop();
            }
        }
    }else{ //ノード上
        fromnode=nodepos;
        nodepos=-1;
        tonode=node;
        kyori=dist[fromnode][tonode];
        ++x;
        if(x==kyori){
            nodepos=node;
            kyori=0;
            fromnode=-1; tonode=-1;
            x=0;
            q.pop();
        }
    }
}

int nextdst(int prenode,int t){
    int fast=MOD,fastno=-1;
    int cnt=0;
    /*
    for(int i=0;i<order.size();++i){
        if(order[i].status==2) ++cnt;
    }
    */
    //cout<<"-------------"<<endl;
    for(int i=0;i<order.size();++i){
        if(order[i].status<=1){
            int tmp=max(order[i].ot-t,dist[prenode][0])+dist[0][order[i].dst];
            tmp*=WEIGHT;
            //cout<<i<<", a:"<<tmp<<endl;
            if(tmp<fast){
                fast=tmp;
                fastno=0;
                //nextorder=i;
            }
        }else if(order[i].status==2){
            int tmp=dist[prenode][order[i].dst];
            //cout<<i<<", b:"<<tmp<<endl;
            if(tmp<fast){
                fast=tmp;
                //fastno=i;
                fastno=order[i].dst;
                //nextorder=i;
            }
        }
    }
    //cout<<"-------------"<<endl;
    return fastno;
}


int main(int argc, char *argv[]) {
    /*
    if(argc==2){
        double tmp=atof(argv[1]);
        WEIGHT=tmp;
        //cerr<<WEIGHT<<endl;
    }
    */

    int N,M; cin>>N>>M;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            to[i][j]=j;
            if(i==j) dist[i][j]=0;
            else dist[i][j]=MOD; //初期化
        }
    }
    int u,v,d;
    for (int i = 0; i < M; ++i) {
        cin>>u>>v>>d; --u; --v;
        dist[u][v]=d;
        dist[v][u]=d;
    }

    //ワーシャルフロイド
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (chmin(dist[i][j], dist[i][k] + dist[k][j])) {
                    to[i][j] = to[i][k];
                }
            }
        }
    }

    vector<int> f(N);
    for (int i = 0; i < N; ++i) {
        cin>>f[i];
    }
    cin>>tmax;
    //cout<<to[0][5]<<endl;
    queue<int> pathdst;
    int delivered=0,ordered=0;
    
    int nowdst=-1;
    for (int t = 0; t < tmax; ++t) {
        //cerr<<"----------- "<<t<<endl;
        //注文情報を受け取る
        int Nnew;
        //vector<int> nid(N),ndst(N);
        int nid,ndst;
        cin>>Nnew;
        for (int i = 0; i < Nnew; ++i) {
            cin>>nid>>ndst;
            order.push_back(Order(t,ndst-1));
            ++ordered;
        }

        //入荷情報
        int Nput,pid; cin>>Nput;
        for (int i = 0; i < Nput; ++i) {
            cin>>pid;
            
            order[pid-1].status=2;
        }

        //ここに処理
        if(delivered==ordered){ //注文がない
            //cerr<<"called"<<endl;
            if(nodepos==0){
                while(!pathdst.empty()) pathdst.pop();
                cout<<-1<<endl;
            }else { //0に向かう
                if (pathdst.empty()) {
                    path(nodepos, 0,pathdst);
                    nowdst=0;
                }
                move(pathdst);
            }
        }else{
            if(pathdst.empty()){
                int dst;
                /* 探索させる
                if(order[itr].status==0){
                    dst=0;
                }else {
                    
                    dst = order[itr].dst;
                }
                nowdst=dst;
                */
                dst=nextdst(nodepos,t);
                //cerr<<"dst:"<<dst<<endl;

                path(nodepos, dst,pathdst);
                //cout<<"run"<<endl;
            }
            //cerr<<"move starts:"<<nodepos<<">"<<pathdst.front()<<endl;
            move(pathdst);
        }

        //判定
        string verdict; cin>>verdict;
        if(verdict=="NG") return 0;
        int Nachive,aid; cin>>Nachive;
        for (int i = 0; i < Nachive; ++i) {
            cin>>aid;
            order[aid-1].status=3;
            delivered++;
            /*
            if(aid-1==itr){
                while(itr<cnt&&order[itr].status==3){
                    ++itr;
                }
                while(!pathdst.empty()) pathdst.pop();
            }
            */
        }
        //cerr<<":"<<delivered<<" "<<ordered<<"|"<<nodepos<<": ("<<fromnode<<","<<tonode<<") d="<<kyori<<", x="<<x<<
        //    ", nowdst="<<nowdst<<", next hop is "<<((pathdst.empty())?-10:pathdst.front())<<endl;
        
    }

    return 0;
}

Measured memory_bytes: 2576