#define LOCAL
#define DEBUG
#define _DEBUG2
#define _DEBUG3
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include "bits/stdc++.h"
#include <sys/time.h>
#include <emmintrin.h>
#include <string>
#include <bitset>

using namespace std;

inline long long GetTSC() {
  long long lo, hi;
  asm volatile ("rdtsc": "=a"(lo), "=d"(hi));
  return lo + (hi << 32);
}
inline double GetSeconds() {
  return GetTSC() / 2.8e9;
}

struct XorShift {
  uint64_t x = 88172645463325252ULL;
  double nl[65536];
  XorShift() {}

  void init(){
    double n2 = 1.0 / 65536*2;
    for(int i=0; i<65536; i++) nl[i] = log(i / 65536.0 + n2);
  }

  void setSeed(uint64_t seed) { x = seed; init(); }

  uint64_t next() {
    x ^= x << 13; x ^= x >> 7; x ^= x << 17;
    return x;
  }

  int nextInt(int n) {
    uint64_t upper = 0xFFFFFFFFFFFFFFFFULL / n * n;
    uint64_t v = next();
    while (v >= upper) v = next();
    return v % n;
  }

  double nextDouble() {
    uint64_t v = next() >> 11; // 53bit
    return (double)v / (1ULL << 53);
  }

  double nextLog() {
    return nl[nextInt(65536)];
  }
};


XorShift xs;
#ifdef LOCAL
const double TO = 29.8 * 1e-1;
#else
const double TO = 29.8;
#endif
const double TO1 = TO * 0.05;

double starttime, gt;
int ttt,ctt,dtt;

const int INF = 1e9;
const int VM = 400;
const int TM = 10000;
const int TM2 = TM * TM;
int V, E, IM;
int C[VM][VM];
int D[VM][VM];
int IFC;
int IC[VM];
vector<int> IF[VM];
vector<int> IS;
vector<int> NE[VM];

struct State{
  int c,t,bi;
  long sc;
  int lt[VM];

  State() {}

  bool operator<(const State &a) const{
    return sc != a.sc ? sc < a.sc : lt[0] < a.lt[0];
  }

  // c == 0
  State copy_t(int _t, int _bi){
    State ns = State();
    ns.c = c;
    ns.t = _t;
    ns.bi = _bi;
    ns.sc = sc;
    for(int i=0; i<V; i++) ns.lt[i] = lt[i];
    ns.lt[0] = _t;
    return ns;
  }

  long next_score(int n){
    long nsc = sc;
    int nt = t + D[c][n];
    if(nt >= TM) return -1;

    int tc = lt[0];
    auto st = upper_bound(IF[n].begin(), IF[n].end(), lt[n]);
    auto et = upper_bound(IF[n].begin(), IF[n].end(), lt[0]);
    for(auto t = st; t < et; t++){
      int f = *t;
      nsc += TM2 - pow(nt - f, 2);
    }
    return nsc;
  }

  State next_state(int n, int _bi, long _sc){
    int nt = t + D[c][n];
    State ns = State();
    ns.c = n;
    ns.t = nt;
    ns.bi = _bi;
    ns.sc = _sc;
    for(int i=0; i<V; i++) ns.lt[i] = lt[i];
    if(n != 0){
      ns.lt[n] = lt[0];
    }else{
      ns.lt[0] = nt;
    }
    return ns;
  }
};

void init(){
  cin >> V >> E;
  for(int i=0; i<V; i++) for(int j=0; j<V; j++) C[i][j] = INF;
  for(int i=0; i<E; i++){
    int u,v,d;
    cin >> u >> v >> d;
    u--; v--;
    C[u][v] = C[v][u] = d;
  }
  int t;
  cin >> t;
  for(int i=0; i<V; i++) IC[i] = 0;
  IFC = 0;
  IS.clear();
  for(int i=0; i<TM; i++){
    int c;
    cin >> c;
    if(c == 0) continue;
    IFC += c;
    IS.emplace_back(i);
    for(int j=0; j<c; j++){
      int n;
      cin >> t >> n;
      IF[n-1].emplace_back(i);
    }
  }
  cerr << "IFC: " << IFC << endl;
  cerr << "VE: " << V << ", " << E << endl;
  for(int i=0; i<V; i++){
    IF[i].emplace_back(TM+1);
    IC[i] = IF[i].size();
  }
  IS.emplace_back(TM);
  /*
  for(int i=2820; i<2830; i++){
    auto t = upper_bound(IS.begin(), IS.end(), i);
    cerr << i << ": " << (*t) << endl;
  }
  // */

  // Warshall Floyd
  for(int i=0; i<V; i++) for(int j=0; j<V; j++) D[i][j] = C[i][j];
  for(int i=0; i<V; i++) D[i][i] = 0;
  for(int k=0; k<V; k++) for(int i=0; i<V; i++) for(int j=0; j<V; j++){
    D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
  }

  for(int i=0; i<V; i++){
    vector<tuple<int, double, int>> ns;
    for(int j=1; j<V; j++){
      if(i == j) continue;
      ns.emplace_back(D[i][j], xs.nextDouble(), j);
    }
    sort(&ns[0], &ns[ns.size()]);
    NE[i].clear();
    if(i != 0) NE[i].emplace_back(0);
    for(auto t : ns){
      NE[i].emplace_back(get<2>(t));
    }
  }
}

vector<State> Q[TM+1];
const int QM = 32;
const int QCM = 16;

void solve(){
  State sq = State();
  sq.c = 0;
  sq.t = 0;
  sq.bi = -1;
  sq.sc = 0;
  for(int i=0; i<V; i++) sq.lt[i] = -1;
  Q[0].push_back(sq);

  for(int i=0; i<TM; i++){
    if(Q[i].size() < 1) continue;
    sort(&Q[i][0], &Q[i][Q[i].size()]);
    const auto q = Q[i];
    int qe = min(int(q.size()), QM);
    for(int qi=qe-1; qi>=0; qi--){
      State t = q[qi];
      int tc = t.c;
      int bi = i*TM + qi;
      int cc = 0;
      for(auto n : NE[tc]){
        long nsc = t.next_score(n);
        if(nsc < 0 || (n > 0 && t.sc == nsc)) continue;
        State ns = t.next_state(n, bi, nsc);
        int nt = ns.t;
        if(Q[nt].size() < QM){
          Q[nt].push_back(ns);
        }else{
          sort(&Q[nt][0], &Q[nt][QM]);
          if (Q[nt][0] < ns){
            Q[nt][0] = ns;
          }
        }
        cc++;
        if(cc >= QCM) break;
      }

      if(tc == 0){
        int nt = *upper_bound(IS.begin(), IS.end(), i);
        State ns = t.copy_t(nt, bi);
        if(Q[nt].size() < QM){
          Q[nt].push_back(ns);
        }else{
          sort(&Q[nt][0], &Q[nt][QM]);
          if (Q[nt][0] < ns){
            Q[nt][0] = ns;
          }
        }
      }
    }
  }
  cerr << "time: " << (GetSeconds() - starttime);
  cerr << " ttt: " << ttt << " ctt: " << ctt << " dtt: " << dtt << endl;
}

void output(){
  long ms = 0;
  int msi = 0;
  for(int i=0; i<=TM; i++){
    if(Q[i].size() > 0){
      int qs = Q[i].size();
      if(ms < Q[i][qs-1].sc){
        ms = Q[i][qs-1].sc;
        msi = i;
      }
    }
  }
  cerr << "ms: " << ms << " log: " << log10(ms) << " msi: " << msi << endl;
  vector<int> R;
  for(int i=msi; i<TM; i++) R.emplace_back(-1);
  State q = Q[msi][Q[msi].size()-1];
  while(q.bi >= 0){
    int ni = q.bi / TM;
    int qi = q.bi % TM;
    State nq = Q[ni][qi];
    if(nq.c == q.c){
      for(int i=nq.t; i<q.t; i++){
        R.emplace_back(-1);
      }
    }else{
      int t = nq.c;
      int c = q.c;
      while(c != t){
        int ct = D[c][t];
        bool ok = false;
        for(int i=0; i<V; i++){
          if(c == i) continue;
          if(C[c][i] + D[i][t] == ct){
            for(int j=0; j<C[c][i]; j++){
              R.emplace_back(c+1);
            }
            c = i;
            ok = true;
            break;
          }
        }
        if(!ok){
          cerr << "err: " << c << " -> " << t << endl;
          break;
        }
      }
    }
    q = nq;
  }
  for(int i=TM-1; i>=0; i--){
    cout << R[i] << endl;
  }
}

int main() {
  starttime = GetSeconds();
  srand((unsigned) time(NULL));
  xs.setSeed(rand() % 65536 + 65537);
  init();
  solve();
  output();

  return 0;
}


Measured memory_bytes: 506004