#include <bits/stdc++.h>
using namespace std;
const int ITERS=25;
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],b[10100],p[10100],oldp[10100],newp[10100],savep[10100],fi[402],fisaved[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,dur_beg;
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;
    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 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) {
      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;
}
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];
          localopt(t,t+ed,x[pos]);
        } else {
          localopt(t,t+z[pos]-ed,y[pos]);
        }
      } else {
        greedy(t,t,-pos);
        localopt(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];
    }
  }
}
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);
  print_result();
  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