#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;

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

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

    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]) {
        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){
        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 main() {


    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 itr=0,cnt=0;
    bool back=false;
    
    int nowdst=-1;
    bool flag=false;
    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));
            ++cnt;
            //order.insert(make_pair(nid,Order(t,ndst)));
        }

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

        //ここに処理
        if(itr==cnt){ //注文がない
            if(nodepos==0){
                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;
                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;

            if(aid-1==itr){
                while(itr<cnt&&order[itr].status==3){
                    ++itr;
                }
                while(!pathdst.empty()) pathdst.pop();
            }
        }
        //cerr<<":"<<itr<<" "<<cnt<<"|"<<nodepos<<": ("<<fromnode<<","<<tonode<<") d="<<kyori<<", x="<<x<<
          //  ", nowdst="<<nowdst<<", next hop is "<<((pathdst.empty())?-10:pathdst.front())<<endl;
        
    }

    return 0;
}

Measured memory_bytes: 2768