#include <bits/stdc++.h>
using namespace std;
const int ITERS=0;
const bool VISIT1=true,FULL=true;
/*const*/ bool UPD_ORDER=true,OLD_GREEDY=false;
const bool REVERSE=true;
const bool GREEDY_WIDE=true;
int n,m,tmax,tmax2,o,cnt,cntres,i,j,k,swaps,x[808],y[808],z[808],d[402][402],ids[402][402],id[10100],dst[10100],av[10100],avsaved[10100],otm[10100],b[10100],p[10100],oldp[10100],newp[10100],savep[10100],fi[402],fisaved[402],freq[402],orders[10100],fg[2][402],fis[2][402];
vector<int> g[402],here[402];  // TODO: orders[i] can be just number, not vector
long long mided,cur,score,dur_beg,f[2][402];
char verdict[5];
int sqr(int x) { return x*x; }
long long deliver_here(int pos, int t) {
  long long score=0;
  for (; fi[pos]<here[pos].size(); fi[pos]++) {
    int i=here[pos][fi[pos]];
    if (av[i]==1) {
      av[i]=2;
      if (t<tmax) score+=tmax2-sqr(t-otm[i]);
      newp[cnt++]=i;
      //fprintf(stderr,"order dst=%d st=%d et=%d\n",pos,otm[i],t);  // i=%d,i
    } else if (av[i]==0) break;
  }
  return score;
}
void dijkstra(int visit1, int pos, int t) {
  for (int ii=1; ii<=n; ii++) {
    f[visit1][ii]=0;
    fg[visit1][ii]=pos;
    fis[visit1][ii]=1;
  }
  for (int ii=2; ii<=n; ii++) {
    int i=ids[pos][ii];
    int j=fi[i];
    for (; j<here[i].size(); j++) {
      int z=here[i][j];
      if (visit1) {
        if (av[z]==0) break;
        if (av[z]==1) f[visit1][i]+=tmax2-sqr(t+d[pos][i]-otm[z]);
      } else {
        if (otm[z]>t) break;
        if (av[z]<=1) f[visit1][i]+=tmax2-sqr(t+d[pos][i]-otm[z]);
      }
    }
    fis[visit1][i]=j;
    if (f[visit1][i]>0 && fg[visit1][i]==pos) fg[visit1][i]=i;
    for (j=0; j<g[i].size(); j++) {
      int e=g[i][j];
      int k=x[e]+y[e]-i;
      if (d[pos][i]+z[e]==d[pos][k]) if (f[visit1][i]>f[visit1][k]) {
        f[visit1][k]=f[visit1][i];
        fg[visit1][k]=fg[visit1][i];
      }
    }
    //fprintf(stderr, "  --> [pos=%d t=%d] %d = %I64d from %d\n",pos,t,i,f[visit1][i],fg[visit1][i]);
  }
  //fflush(stderr);
}
long long greedy(int init_t, int t, int pos) {
  //fprintf(stderr, "Greedy run t=%d pos=%d cntres=%d o=%d\n",init_t,pos,cntres,o);
  //fflush(stderr);
  long long score=0;
  bool visit_1=false;
  for (int i=1; i<=n; i++) {
    for (fi[i]=0; fi[i]<here[i].size(); fi[i]++) if (av[here[i][fi[i]]]<2) break;
    fisaved[i]=fi[i];
    //if (fi[i]<here[i].size()) fprintf(stderr,"here %d size = %d : order %d\n",i,int(here[i].size()),here[i][fi[i]]);
  }
  for (int i=0; i<o; i++) avsaved[i]=av[i];
  cnt=cntres;
  for (int nxto=-1; cnt<o; ) {
    score+=deliver_here(pos,t);
    if (pos==1 && !visit_1) {
      for (int i=init_t; i>=0; i--) if (orders[i]>=0) {
        //fprintf(stderr,"visit time=%d order=%d (%d)\n",i,orders[i],av[orders[i]]);
        if (av[orders[i]]==0) av[orders[i]]=1; else break;
      }
      visit_1=true;
    }
    if (nxto==-1 || av[nxto]==2) {
      //fprintf(stderr,"-----\n");
      nxto=-1;
      dijkstra(0,pos,t);
      dijkstra(1,1,t+d[pos][1]);
      int tm_1=t+d[pos][1];
      long long best_score=0;
      long long best_tm=1;
      for (int i=1; i<=n; i++) {
        int tm_i0=tm_1+d[1][i];
        int tm_i1=t+d[pos][i];
        long long score_i0=f[1][i];
        long long score_i1=f[0][i];
        //if (score_i0!=0) fprintf(stderr,"score direct %d = %I64d/%d = %.2lf (from %d)\n",i,score_i0,tm_i0-t,double(score_i0)/tm_i0-t,fg[1][i]);
        //if (score_i1!=0) fprintf(stderr,"score base %d = %I64d/%d = %.2lf (from %d)\n",i,score_i1,tm_i1-t,double(score_i1)/tm_i1-t,fg[0][i]);
        if (score_i0*best_tm>best_score*(tm_i0-t) && (tm_i0<tmax || best_score==0 || t+best_tm>=tmax)) {
          int pv=fg[1][i];
          int where=fis[1][pv]-1;
          if (where>=0 && where<here[pv].size() && av[here[pv][where]]==0) {
            best_score=score_i0;
            best_tm=tm_i0-t;
            nxto=here[pv][where];
            //fprintf(stderr,"best i0: %d [%d %d %d]\n",nxto,av[0],av[1],av[2]);
          }
        }
        if (score_i1*best_tm>best_score*(tm_i1-t) && (tm_i1<tmax || best_score==0 || t+best_tm>=tmax)) {
          int pv=fg[0][i];
          int where=fis[0][pv]-1;
          if (where>=0 && where<here[pv].size()) {
            best_score=score_i1;
            best_tm=tm_i1-t;
            nxto=here[pv][where];
            //fprintf(stderr,"best i1: %d\n",nxto);
          }
        }
        //fflush(stderr);
      }
      if (nxto==-1) nxto=1;
    }
    int ds=(av[nxto]==1)?dst[nxto]:1;
    //fprintf(stderr, "nxto=%d; av[nxto]=%d; ds=%d; visit_1=%d; t=%d; otm=%d; init_t=%d\n",nxto,av[nxto],ds,int(visit_1),t,otm[nxto],init_t);
    //fflush(stderr);
    if (VISIT1 && !visit_1) {
      if (pos!=1 && ds!=1 && d[pos][ds]==d[pos][1]+d[1][ds]) ds=1;
    }
    if (pos!=ds) {
      for (int i=0; i<g[pos].size(); i++) {
        int e=g[pos][i];
        int nxt=x[e]+y[e]-pos;
        if (d[ds][pos]==d[ds][nxt]+z[e]) {
          ds=nxt;
          break;
        }
      }
      t+=d[pos][ds];
      pos=ds;
    } else t++;
  }
  for (int i=cntres; i<o; i++) p[i]=newp[i];
  for (int i=0; i<o; i++) av[i]=avsaved[i];
  //fprintf(stderr,"Greedy: score=%I64d; cnt=%d\n",score,cnt);
  return score;
}
long long calc_score(int init_t, int t, int pos) {
  long long score=0;
  for (int i=1; i<=n; i++) fi[i]=fisaved[i];
  for (int i=0; i<o; i++) avsaved[i]=av[i];
  bool visit_1=false;
  cnt=cntres;
  for (int cur=cntres; cur<o && t<tmax; ) {
    //fprintf(stderr,"#time=%d; position=%d; nxt=%d\n",t,pos,dst[p[cur]]);
    score+=deliver_here(pos,t);
    for (; cur<o && av[p[cur]]==2; cur++);
    if (cur>=o) break;
    if (pos==1 && !visit_1) {
      for (int i=init_t; i>=0; i--) if (orders[i]>=0) {
        //fprintf(stderr,"visit time=%d order=%d (%d)\n",i,orders[i],av[orders[i]]);
        if (av[orders[i]]==0) av[orders[i]]=1; else break;
      }
      visit_1=true;
    }
    int ds=(av[p[cur]]==1)?dst[p[cur]]:1;
    if (VISIT1 && !visit_1) {
      if (pos!=1 && ds!=1 && d[pos][ds]==d[pos][1]+d[1][ds]) ds=1;
    }
    if (pos!=ds) {
      for (int i=0; i<g[pos].size(); i++) {
        int e=g[pos][i];
        int nxt=x[e]+y[e]-pos;
        if (d[ds][pos]==d[ds][nxt]+z[e]) {
          ds=nxt;
          break;
        }
      }
      t+=d[pos][ds];
      pos=ds;
    } else t++;
  }
  int num=cnt;
  for (int i=cntres; i<o; i++) if (av[p[i]]!=2) newp[num++]=p[i];
  if (num!=o) puts("!!!!!");
  for (int i=0; i<o; i++) av[i]=avsaved[i];
  return score;
}
void upd_order() {
  for (int i=cntres; i<o; i++) p[i]=newp[i];
}
void localopt(int init_t, int t, int pos) {
  score=calc_score(init_t,t,pos);
  for (int i=cntres; i<o; i++) oldp[i]=p[i];
  //fprintf(stderr,"score=%I64d; cnt=%d; o=%d\n",score,cnt,o);
  for (int it=0; it<ITERS; it++) {
    int len=o-cntres;
    i=rand()%len;
    if (REVERSE) {
      j=rand()%len;
      if (j>=i) j++;
      if (i>j) swap(i,j);
      reverse(p+cntres+i,p+cntres+j);
    } else {
      j=rand()%(len-1);
      if (j>=i) j++;
      swap(p[cntres+i],p[cntres+j]);
    }
    long long cur=calc_score(init_t,t,pos);
    if (cur<score) {
      if (REVERSE) {
        reverse(p+cntres+i,p+cntres+j);
      } else {
        if (UPD_ORDER) {
          ////for (int i=cntres; i<o; i++) p[i]=newp[i];
          upd_order();
        }
        swap(p[i],p[j]);
        //swap(p[i],p[i+1]);
      }
    } else {
      swaps++;
      //fprintf(stderr,"len=%d\n",j-i);
      score=cur;
    }
    /*if ((it&511)==0) {
      auto dur=chrono::high_resolution_clock::now()-dur_beg;
      auto ms=chrono::duration_cast<chrono::milliseconds>(dur).count();
      //fprintf(stderr,"iter %d; %d ms\n",it,ms);
      //if (ms>22000) UPD_ORDER=false;
      if (ms>29450) break;
    }*/
  }
  score=calc_score(init_t,t,pos);
  for (int i=cntres; i<o; i++) {
    savep[i]=p[i];
    p[i]=oldp[i];
  }
  cur=calc_score(init_t,t,pos);
  if (cur<=score) for (int i=cntres; i<o; i++) p[i]=savep[i]; else score=cur;
}
long long old_greedy(int init_t, int t, int pos) {
  //fprintf(stderr, "Greedy run t=%d pos=%d cntres=%d o=%d\n",init_t,pos,cntres,o);
  //fflush(stderr);
  long long score=0;
  bool visit_1=false;
  for (int i=1; i<=n; i++) {
    for (fi[i]=0; fi[i]<here[i].size(); fi[i]++) if (av[here[i][fi[i]]]<2) break;
    fisaved[i]=fi[i];
    //if (fi[i]<here[i].size()) fprintf(stderr,"here %d size = %d : order %d\n",i,int(here[i].size()),here[i][fi[i]]);
  }
  for (int i=0; i<o; i++) avsaved[i]=av[i];
  cnt=cntres;
  for (int nxto=-1; cnt<o; ) {
    //fprintf(stderr,"#time=%d; position=%d; nxto=%d; cntres=%d; cnt=%d; o=%d\n",t,pos,nxto,cntres,cnt,o);
    //fflush(stderr);
    score+=deliver_here(pos,t);
    if (pos==1 && !visit_1) {
      for (int i=init_t; i>=0; i--) if (orders[i]>=0) {
        //fprintf(stderr,"visit time=%d order=%d (%d)\n",i,orders[i],av[orders[i]]);
        if (av[orders[i]]==0) av[orders[i]]=1; else break;
      }
      visit_1=true;
    }
    if (nxto==-1 || av[nxto]==2) {
      nxto=-1;
      int tm_1=t+d[pos][1];
      long long best_score=0;
      long long best_tm=1;
      for (int i=1; i<=n; i++) {
        int tm_i0=tm_1+d[1][i];
        int tm_i1=t+d[pos][i];
        long long score_i0=0,score_i1=0,j;
        for (j=fi[i]; j<here[i].size(); j++) {
          int z=here[i][j];
          if (otm[z]>tm_1) break;
          //fprintf(stderr,"i=%d j=%d z=%d | otm=%d avz=%d | %d..%d\n",i,j,z,otm[z],av[z],t,tm_1);
          if (av[z]<=1) score_i0+=tmax2-sqr(tm_i0-otm[z]);
          if (av[z]==1) score_i1+=tmax2-sqr(tm_i1-otm[z]);
        }
        if (score_i0*best_tm>best_score*(tm_i0-t) && (tm_i0<tmax || best_score==0 || t+best_tm>=tmax)) {
          best_score=score_i0;
          best_tm=tm_i0-t;
          nxto=here[i][j-1];
          //fprintf(stderr,"best i0: %d\n",nxto);
        }
        if (score_i1*best_tm>best_score*(tm_i1-t) && (tm_i1<tmax || best_score==0 || t+best_tm>=tmax)) {
          best_score=score_i1;
          best_tm=tm_i1-t;
          nxto=here[i][fi[i]];
          //fprintf(stderr,"best i1: %d\n",nxto);
        }
      }
      if (nxto==-1) nxto=1;
    }
    int ds=(av[nxto]==1)?dst[nxto]:1;
    //fprintf(stderr, "nxto=%d; av[nxto]=%d; ds=%d; visit_1=%d; t=%d; otm=%d; init_t=%d\n",nxto,av[nxto],ds,int(visit_1),t,otm[nxto],init_t);
    //fflush(stderr);
    if (VISIT1) {
      if (pos!=1 && ds!=1 && d[pos][ds]==d[pos][1]+d[1][ds]) ds=1;
    }
    if (pos!=ds) {
      for (int i=0; i<g[pos].size(); i++) {
        int e=g[pos][i];
        int nxt=x[e]+y[e]-pos;
        if (d[ds][pos]==d[ds][nxt]+z[e]) {
          ds=nxt;
          break;
        }
      }
      t+=d[pos][ds];
      pos=ds;
    } else t++;
  }
  for (int i=cntres; i<o; i++) p[i]=newp[i];
  for (int i=0; i<o; i++) av[i]=avsaved[i];
  //fprintf(stderr,"Greedy: score=%I64d; cnt=%d\n",score,cnt);
  return score;
}
long long chgreedy(int init_t, int t, int pos) {
  if (OLD_GREEDY) {
    return old_greedy(init_t,t,pos);
  } else {
    return greedy(init_t,t,pos);
  }
}
void print_result() {
    auto dur_beg=chrono::high_resolution_clock::now();
  score=0;
  int cur=0,pos=-1,ed=0,avail=0;
  for (int i=0; i<tmax; i++) av[i]=0;
  for (int t=0; t<tmax; t++) {
    /*if ((t&511)==0) {
    fprintf(stderr,"#time=%d; position=%d; cntres=%d; cnt=%d; o=%d\n",t,pos,cntres,cnt,o);
    fflush(stderr);
    }*/
    scanf("%d",&cnt);
    if (cnt) {
      scanf("%d%d",&id[o],&dst[o]);
      b[id[o]]=o;
      here[dst[o]].push_back(o);
      orders[t]=o;
      //fprintf(stderr,"order %d @ %d appeared (pos=%d, t=%d) [%d]\n",o,dst[o],pos,t,d[1][dst[o]]);
      //fflush(stderr);
      //fprintf(stderr,"orders[%d]<-%d\n",t,o);
      otm[o++]=t;
      if (pos>=0) {
        auto dur=chrono::high_resolution_clock::now()-dur_beg;
        auto ms=chrono::duration_cast<chrono::milliseconds>(dur).count();
        if (ms>19510) OLD_GREEDY=true;
        long long score1=chgreedy(t,t+ed,x[pos]);
        for (int i=cntres; i<o; i++) savep[i]=p[i];
        long long score2=chgreedy(t,t+z[pos]-ed,y[pos]);
        if (score1>score2) {
          for (int i=cntres; i<o; i++) p[i]=savep[i];
          //if (FULL || t*2<=tmax) localopt(t,t+ed,x[pos]);
        } else {
          //if (FULL || t*2<=tmax) localopt(t,t+z[pos]-ed,y[pos]);
        }
      } else {
        chgreedy(t,t,-pos);
        //if (FULL || t*2<=tmax) localopt(t,t,-pos);
      }
      cur=cntres;
    } else orders[t]=-1;
    scanf("%d",&cnt);
    avail+=cnt;
    for (int j=0; j<cnt; j++) {
      scanf("%d",&k);
      av[b[k]]=1;
      //fprintf(stderr,"order %d @ %d available (pos=%d, t=%d)\n",b[k],dst[b[k]],pos,t);
      //fflush(stderr);
    }
    // printf("time %d: pos %d %d\n",t,pos,ed);
    if (pos<0) {
      for (; cur<o && av[p[cur]]==2; cur++);
    }
    int ds=(cur<o && av[p[cur]]==1)?dst[p[cur]]:1;
    //fprintf(stderr,"move towards %d at time %d\n",ds,t);
    //fflush(stderr);
    // printf("pcur=%d ds=%d\n",p[cur],ds);
    if (pos<0) {
     if (pos==-ds) {
       puts("-1");
     } else {
      if (VISIT1 && avail<o) {
        if (pos!=-1 && ds!=1 && d[-pos][ds]==d[-pos][1]+d[1][ds]) ds=1;
      }
      for (int i=0; i<g[-pos].size(); i++) {
        int e=g[-pos][i];
        int nxt=x[e]+y[e]+pos;
        //printf(" nxt=%d; %d =?= %d + %d\n",nxt,d[ds][-pos],d[ds][nxt],z[e]);
        if (d[ds][-pos]==d[ds][nxt]+z[e]) {
          printf("%d\n",nxt);
          if (z[e]>1) {
            ed=(x[e]==-pos)?1:(z[e]-1);
            pos=e;
          } else pos=-nxt;
          break;
        }
      }
     }
    } else {
      if (d[ds][x[pos]]+ed<d[ds][y[pos]]+z[pos]-ed) {
        printf("%d\n",x[pos]);
        if (ed==1) pos=-x[pos]; else ed--;
      } else {
        printf("%d\n",y[pos]);
        if (ed+1==z[pos]) pos=-y[pos]; else ed++;
      }
    }
    fflush(stdout);
    scanf("%s",verdict);
    if (verdict[0]=='N') break;
    scanf("%d",&cnt);
    cntres+=cnt;
    for (int j=0; j<cnt; j++) {
      scanf("%d",&k);
      av[b[k]]=2;
      score+=sqr(tmax2)-sqr(t+1-otm[b[k]]);
      //fprintf(stderr,"order %d @ %d scored (pos=%d, t=%d)\n",b[k],dst[b[k]],pos,t);
      //fflush(stderr);
      //res[cntres++]=b[k];
    }
  }
}
bool cmp(int x, int y) {
  return d[i][x]<d[i][y];
}
int main() {
  srand(371);
  scanf("%d%d",&n,&m);
  memset(d,10,sizeof(d));
  for (i=1; i<=n; i++) d[i][i]=0;
  for (i=1; i<=m; i++) {
    scanf("%d%d%d",&x[i],&y[i],&z[i]);
    mided+=z[i];
    d[x[i]][y[i]]=d[y[i]][x[i]]=z[i];
    g[x[i]].push_back(i);
    g[y[i]].push_back(i);
  }
  mided/=m;
  for (i=1; i<=n; i++) scanf("%d",&freq[i]);
  for (k=1; k<=n; k++) for (i=1; i<=n; i++) for (j=1; j<=n; j++)
    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  for (i=1; i<=n; i++) {
    for (j=1; j<=n; j++) ids[i][j]=j;
    sort(ids[i]+1,ids[i]+n+1,cmp);
  }
  //for (i=1; i<=n; i++, fprintf(stderr," == %d\n",i)) for (j=1; j<=n; j++) fprintf(stderr,"%d(%d) ",d[i][ids[i][j]],ids[i][j]);
  //fflush(stderr);
  //return 0;
  scanf("%d",&tmax);
  tmax2=sqr(tmax);
  print_result();
  return 0;
}


Measured memory_bytes: 2772