#include <bits/stdc++.h>
using namespace std;
const int ITERS=140000;
const bool VISIT1=true;
/*const*/ bool UPD_ORDER=true,PRINT_ORDER=false;
const bool REVERSE=true;
const bool GREEDY_WIDE=true;
int n,m,tmax,tmax2,o,cnt,i,j,k,swaps,x[808],y[808],z[808],d[402][402],id[10100],dst[10100],av[10100],otm[10100],p[10100],oldp[10100],savep[10100],newp[10100],orders[10100],fi[402];
vector<int> g[402],here[402];
long long mided,cur,score;
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;
      if (PRINT_ORDER) fprintf(stderr,"order dst=%d st=%d et=%d score=%I64d\n",pos,otm[i],t,score);  // i=%d,i
    } else if (av[i]==0) break;
  }
  return score;
}
void init() {
  long long score=cnt=0;
  int pos=1,lst=-1,t=0;
  for (int i=1; i<=n; i++) fi[i]=0;
  for (int i=0; i<o; i++) av[i]=0;
  for (int nxto=-1; cnt<o; ) {
    //fprintf(stderr,"#time=%d; position=%d; nxto=%d\n",t,pos,nxto);
    score+=deliver_here(pos,t);
    if (pos==1) {
      for (int i=lst+1; i<=t && i<tmax; i++) if (orders[i]>=0) av[orders[i]]=1;
      lst=t;
    }
    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],j;
        long long score_i0=0,score_i1=0;
        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 (fi[i]<j) fprintf(stderr,"   vertex %d: %I64d %d; %I64d %d\n",j,score_i0,tm_i0,score_i1,tm_i1);
        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);
        }
      }
      //fprintf(stderr, "nxto=%d; t=%d; otm=%d\n", nxto,t,otm[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;
    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 (i=0; i<o; i++) p[i]=newp[i];
  fprintf(stderr,"Greedy: score=%I64d; cnt=%d\n",score,cnt);
}
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=cnt=0;
  int cur=0,pos=-1,ed=0,lst=-1;
  for (int i=1; i<=n; i++) fi[i]=0;
  for (int i=0; i<o; i++) av[i]=0;
  for (int t=0; t<tmax; t++) {
    // printf("time %d: pos %d %d\n",t,pos,ed);
    if (pos<0) {
      score+=deliver_here(-pos,t);
      for (; cur<o && av[p[cur]]==2; cur++);
      if (cur>=o) {
        puts("-1");
        continue;
      }
      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;
    // printf("pcur=%d ds=%d\n",p[cur],ds);
    if (pos<0) {
      if (pos==-ds) {
        puts("-1");
        continue;
      }
      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++;
      }
    }
  }
}
void upd_order() {
  for (int i=0; i<o; i++) {
    oldp[i]=p[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 (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]);
  scanf("%d",&tmax);
  tmax2=sqr(tmax);
  for (i=0; i<tmax; i++) {
    scanf("%d",&cnt);
    if (cnt) {
      scanf("%d%d",&id[o],&dst[o]);
      here[dst[o]].push_back(o);
      orders[i]=o;
      otm[o++]=i;
    } else orders[i]=-1;
  }
  init();
  score=calc_score();
  for (i=0; i<o; i++) oldp[i]=p[i];
  //if (UPD_ORDER) upd_order();
  fprintf(stderr,"score=%I64d; cnt=%d; o=%d\n",score,cnt,o);
  for (int it=0; it<ITERS; it++) {
    int zrnd=1,len;//rand()%50;
    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);
      //zrnd=rand()%3;
      //len=j-i;
      //if (zrnd || j+len>=o || len>4) {
        reverse(p+i,p+j);
      /*} else {
        for (int e=0; e<len; e++) swap(p[i+e],p[j+e]);
      }*/
    } else {
      j=rand()%(o-1);
      if (j>=i) j++;
      swap(p[i],p[j]);
      /*if (i==0) i=rand()%(o-1);
      swap(p[i],p[i+1]);*/
    }
    cur=calc_score();
    if (cur<score) {
      if (REVERSE) {
        //if (zrnd || j+len>=o || len>4)
          reverse(p+i,p+j);
        /*else {
          for (int e=0; e<len; e++) swap(p[i+e],p[j+e]);
        }*/
      } else {
        if (UPD_ORDER) 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;
    }
  }
  fprintf(stderr,"%d swaps made; score=%I64d; cnt=%d\n",swaps,score,cnt);
  // TODO: SA?
  //PRINT_ORDER=true;
  score=calc_score();
  for (i=0; i<o; i++) {
    savep[i]=p[i];
    p[i]=oldp[i];
  }
  cur=calc_score();
  if (cur<=score) for (i=0; i<o; i++) p[i]=savep[i]; else score=cur;
  //for (i=0; i<o; i++) printf("p[%d]=%d\n",i,p[i]);
  //score=calc_score();
  fprintf(stderr,"calc_score: %d swaps made; score=%I64d; cnt=%d\n",swaps,score,cnt);
  print_result();
  fprintf(stderr,"print_result: %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);
  return 0;
}


Measured memory_bytes: 1280