#include <bits/stdc++.h>
using namespace std;
const int ITERS=140000;
const bool VISIT1=true;
/*const*/ bool UPD_ORDER=true;
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],id[10100],dst[10100],av[10100],avsaved[10100],otm[10100],p[10100],b[10100],newp[10100],savep[10100],fi[402],freq[402],orders[10100];
vector<int> g[402],here[402];  // TODO: orders[i] can be just number, not vector
long long mided,cur,score;
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;
}
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;
    //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);
        }
      }
      /*for (int i=0; i<o; i++) if (av[i]!=2) {
        if (nxto==-1) { nxto=i; continue; }
        int nlst_new=(av[i]==0)?max(t+d[pos][1],otm[i]):lst;
        int tm_i_new=(av[i]==0)?(nlst_new+d[1][dst[i]]):(t+d[pos][dst[i]]);
        int tm_nxto_new=(otm[nxto]>nlst_new)?(max(tm_i_new+d[dst[i]][1],otm[nxto])+d[1][dst[nxto]]):(tm_i_new+d[dst[i]][dst[nxto]]);
        int nlst_old=(av[nxto]==0)?max(t+d[pos][1],otm[nxto]):lst;
        int tm_nxto_old=(av[nxto]==0)?(nlst_old+d[1][dst[nxto]]):(t+d[pos][dst[nxto]]);
        int tm_i_old=(otm[i]>nlst_new)?(max(tm_nxto_old+d[dst[nxto]][1],otm[i])+d[1][dst[i]]):(tm_nxto_old+d[dst[nxto]][dst[i]]);
        if (tm_i_new>=tmax && tm_nxto_old>=tmax || GREEDY_WIDE) {
          if (sqr(tm_i_new-otm[i])+sqr(tm_nxto_new-otm[nxto])<sqr(tm_nxto_old-otm[nxto])+sqr(tm_i_old-otm[i])) nxto=i;
        } else {
          int score_new=(tm_i_new<tmax)?tmax2-sqr(tm_i_new-otm[i]):0;
          if (tm_nxto_new<tmax) score_new+=tmax2-sqr(tm_nxto_new-otm[nxto]);
          int score_old=(tm_nxto_old<tmax)?tmax2-sqr(tm_nxto_old-otm[nxto]):0;
          if (tm_i_old<tmax) score_old+=tmax2-sqr(tm_i_old-otm[i]);
          if (score_new>score_old) nxto=i;
        }
      }*/
      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 calc_score() {
  long long score=cnt=0;
  int pos=1,lst=-1;
  for (int i=1; i<=n; i++) fi[i]=0;
  for (int i=0; i<o; i++) av[i]=0;
  for (int cur=0, t=0; 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) {
      for (int i=lst+1; i<=t; i++) if (orders[i]>=0) av[orders[i]]=1;
      lst=t;
    }
    int ds=(av[p[cur]]==1)?dst[p[cur]]:1;
    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++;
  }
  int num=cnt;
  for (int i=0; i<o; i++) if (av[p[i]]!=2) newp[num++]=p[i];
  if (num!=o) puts("!!!!!");
  return score;
}*/
void print_result() {
  score=0;
  int cur=0,pos=-1,ed=0;
  for (int i=0; i<tmax; i++) av[i]=0;
  for (int t=0; t<tmax; t++) {
    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,"orders[%d]<-%d\n",t,o);
      otm[o++]=t;
      if (pos>=0) {
        long long score1=greedy(t,t+ed,x[pos]);
        for (int i=cntres; i<o; i++) savep[i]=p[i];
        long long score2=greedy(t,t+z[pos]-ed,y[pos]);
        if (score1>score2) for (int i=cntres; i<o; i++) p[i]=savep[i];
      } else greedy(t,t,-pos);
      cur=cntres;
    } else orders[t]=-1;
    scanf("%d",&cnt);
    for (int j=0; j<cnt; j++) {
      scanf("%d",&k);
      av[b[k]]=1;
    }
    // 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;
    // printf("pcur=%d ds=%d\n",p[cur],ds);
    if (pos<0) {
     if (pos==-ds) {
       puts("-1");
     } else {
      if (VISIT1) {
        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]]);
      //res[cntres++]=b[k];
    }
  }
}
void upd_order() {
  for (int i=0; i<o; i++) p[i]=newp[i];
}
int main() {
  auto dur_beg=chrono::high_resolution_clock::now();
  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++, puts("")) for (j=1; j<=n; j++) printf("%d ",d[i][j]);
  scanf("%d",&tmax);
  tmax2=sqr(tmax);
  /*for (i=0; i<tmax; i++) {
    
  }
  init();
  score=calc_score();
  //if (UPD_ORDER) upd_order();
  fprintf(stderr,"score=%I64d; cnt=%d; o=%d\n",score,cnt,o);
  for (int it=0; it<ITERS; it++) {
    i=rand()%o;
    if (REVERSE) {
      //j=i+1+rand()%min(o/3,o-i);
      j=rand()%o;
      if (j>=i) j++;
      if (i>j) swap(i,j);
      reverse(p+i,p+j);
    } else {
      j=rand()%(o-1);
      if (j>=i) j++;
      swap(p[i],p[j]);
    }
    cur=calc_score();
    if (cur<score) {
      if (REVERSE) {
        reverse(p+i,p+j);
      } else {
        swap(p[i],p[j]);
      }
    } else {
      if (UPD_ORDER) upd_order();
      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;
    }
  }
  fprintf(stderr,"%d swaps made; score=%I64d; cnt=%d\n",swaps,score,cnt);*/
  // TODO: type of rand_iterations + SA/HC
  print_result();  // TODO: print best
  fprintf(stderr,"%d swaps made; score=%I64d; cnt=%d\n",swaps,score,cnt);
  auto dur=chrono::high_resolution_clock::now()-dur_beg;
  auto ms=chrono::duration_cast<chrono::milliseconds>(dur).count();
  fprintf(stderr,"%d ms\n",ms);
  fflush(stderr);
  return 0;
}


Measured memory_bytes: 2132