#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("sse4.2")

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <functional>
#include <numeric>
#include <random>
#include <chrono>
#include <cstring>
#include <climits>
#include <cassert>

using namespace std;

typedef long long int ll;

struct xorshift64 {
  unsigned long long int x = 88172645463325252ULL;
  inline unsigned int nextInt() {
    x = x ^ (x << 7);
    return x = x ^ (x >> 9);
  }
  inline unsigned int nextIntMod(unsigned long long int mod) {
    x = x ^ (x << 7);
    x = x ^ (x >> 9);
    return ((x & 0x00000000ffffffff) * mod) >> 32;
  }
  inline double nextDouble() {
    x = x ^ (x << 7);
    x = x ^ (x >> 9);
    return (double)x * 5.42101086242752217e-20;
  }
};

struct timer {
  double t = 0.0;
  void restart() {
    t = now();
  }
  double time() {
    return now() - t;
  }
  double now() {
    unsigned long long l, h;
    __asm__ ("rdtsc" : "=a"(l), "=d"(h));
    return (double)(l | h << 32) * 3.5714285714285715e-10; // 1 / 2.8e9
  }
};

//#define DEBUG

xorshift64 theRandom;
timer theTimer;

constexpr int tMax = 10000;
constexpr int vMax = 400;

int V, E;

int graph[vMax][vMax];
list<pair<int, int> > graphAdj[vMax];
int dist[vMax][vMax];
vector<int> route[vMax][vMax];

vector<vector<int> > order(vMax);
int orderCount[vMax];

vector<int> visitOrder, bestVisitOrder;
int totalOrderCount;
int nowEnded, lastEnded;

ll calcScore() {
  int t = 0;
  ll score = 0;
  int now = 0;
  int lastSupply = 0;
  vector<int> delivered(V);
  int i = 0;
  for (i = 0; i < totalOrderCount; i++) {
    int next = visitOrder[i];
    if (delivered[next] >= orderCount[next]) continue; // order fulfilled
    if (lastSupply < order[next][delivered[next]]) { // no order yet
      for (int j = 1; j < route[now][0].size(); j++) {
        t += dist[route[now][0][j-1]][route[now][0][j]]; // move
        if (t > tMax) break; // out of time
        while (delivered[route[now][0][j]] < orderCount[route[now][0][j]]) {
          if (lastSupply >= order[route[now][0][j]][delivered[route[now][0][j]]]) {
            score += (tMax * tMax) - ((t - order[route[now][0][j]][delivered[route[now][0][j]]]) * (t - order[route[now][0][j]][delivered[route[now][0][j]]]));
            delivered[route[now][0][j]]++; // fill an order
          }
          else break;
        }
      }
      t = max(t, order[next][delivered[next]]);
      lastSupply = t;
      now = 0;
    }
    for (int j = 1; j < route[now][next].size(); j++) {
      t += dist[route[now][next][j-1]][route[now][next][j]]; // move
      if (t > tMax) break; // out of time
      while (delivered[route[now][next][j]] < orderCount[route[now][next][j]]) {
        if (lastSupply >= order[route[now][next][j]][delivered[route[now][next][j]]]) {
          score += (tMax * tMax) - ((t - order[route[now][next][j]][delivered[route[now][next][j]]]) * (t - order[route[now][next][j]][delivered[route[now][next][j]]]));
          delivered[route[now][next][j]]++; // fill an order
        }
        else break;
      }
    }
    if (t > tMax) break; // out of time
    now = next;
  }
  nowEnded = i;
  return score;
}

vector<int> getAnswer() {
  int t = 0;
  ll score = 0;
  int now = 0;
  int lastSupply = 0;
  vector<int> delivered(V);
  vector<int> ans(tMax, -1);
  int i = 0;
  for (i = 0; i < totalOrderCount; i++) {
    int next = visitOrder[i];
    if (delivered[next] >= orderCount[next]) continue; // order fulfilled
    if (lastSupply < order[next][delivered[next]]) { // no order yet
      for (int j = 1; j < route[now][0].size(); j++) {
        int lastT = t;
        t += dist[route[now][0][j-1]][route[now][0][j]]; // move
        if (t > tMax) break; // out of time
        for (int k = lastT; k < t; k++) ans[k] = route[now][0][j] + 1;
        while (delivered[route[now][0][j]] < orderCount[route[now][0][j]]) {
          if (lastSupply >= order[route[now][0][j]][delivered[route[now][0][j]]]) {
            score += (tMax * tMax) - ((t - order[route[now][0][j]][delivered[route[now][0][j]]]) * (t - order[route[now][0][j]][delivered[route[now][0][j]]]));
            delivered[route[now][0][j]]++; // fill an order
          }
          else break;
        }
      }
      t = max(t, order[next][delivered[next]]);
      lastSupply = t;
      now = 0;
    }
    for (int j = 1; j < route[now][next].size(); j++) {
      int lastT = t;
      t += dist[route[now][next][j-1]][route[now][next][j]]; // move
      if (t > tMax) break; // out of time
      for (int k = lastT; k < t; k++) ans[k] = route[now][next][j] + 1;
      while (delivered[route[now][next][j]] < orderCount[route[now][next][j]]) {
        if (lastSupply >= order[route[now][next][j]][delivered[route[now][next][j]]]) {
          score += (tMax * tMax) - ((t - order[route[now][next][j]][delivered[route[now][next][j]]]) * (t - order[route[now][next][j]][delivered[route[now][next][j]]]));
          delivered[route[now][next][j]]++; // fill an order
        }
        else break;
      }
    }
    if (t > tMax) break; // out of time
    now = next;
  }
  return ans;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  theTimer.restart();

  for (int i = 0; i < vMax; i++) {
    for (int j = 0; j < vMax; j++) {
      graph[i][j] = tMax;
      dist[i][j] = tMax;
    }
    graph[i][i] = 0;
    dist[i][i] = 0;
  }

  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int u, v, d;
    cin >> u >> v >> d;
    graph[u-1][v-1] = d;
    graph[v-1][u-1] = d;
    graphAdj[u-1].emplace_back(d, v-1);
    graphAdj[v-1].emplace_back(d, u-1);
    dist[u-1][v-1] = d;
    dist[v-1][u-1] = d;
  }
  int _tMax;
  cin >> _tMax;
  for (int i = 0; i < tMax; i++) {
    int c;
    cin >> c;
    for (int j = 0; j < c; j++) {
      int _id, d;
      cin >> _id >> d;
      order[d-1].push_back(i);
    }
  }

  // calculate dist
  for (int i = 0; i < V; i++) {
    priority_queue<pair<int, vector<int> >, vector<pair<int, vector<int> > >, greater<pair<int, vector<int> > > > que;
    vector<bool> visited(V);
    que.emplace(0, vector<int>({i}));
    while (!que.empty()) {
      auto now = que.top();
      que.pop();
      int v = now.second[now.second.size()-1];
      if (visited[v]) continue;
      visited[v] = true;
      dist[i][v] = now.first;
      route[i][v] = now.second;
      for (auto &adj: graphAdj[v]) {
        auto next = now;
        next.first += adj.first;
        next.second.push_back(adj.second);
        que.push(next);
      }
    }
  }

  for (int i = 0; i < V; i++) {
    orderCount[i] = order[i].size();
    for (int k = 0; k < orderCount[i]; k++) visitOrder.push_back(i);
  }
  bestVisitOrder = visitOrder;
  totalOrderCount = visitOrder.size();

  ll score = calcScore();
  ll lastScore = score;
  ll bestScore = score;
  lastEnded = nowEnded;

  double temperature = 1.0e10;
  double decayRate = 2.0e-5;

  double timeLimit = 29.900;

  int iterCount = 0;

  while (theTimer.time() < timeLimit) {
    if (theRandom.nextDouble() < 0.001) { // swap
      int v1 = theRandom.nextIntMod(totalOrderCount);
      int v2 = theRandom.nextIntMod(totalOrderCount);
      if (v1 == v2 || visitOrder[v1] == visitOrder[v2] || lastEnded < min(v1, v2)) continue;
      swap(visitOrder[v1], visitOrder[v2]);

      score = calcScore();

      #ifdef DEBUG
      if (iterCount % 10000 == 0) cerr << iterCount << " " << score << " " << lastScore << " " << bestScore << " " << temperature << endl;
      #endif

      if (score >= lastScore) {
        lastScore = score;
        if (score >= bestScore) {
          bestScore = score;
          bestVisitOrder = visitOrder;
        }
        lastEnded = nowEnded;
      }
      else if (theRandom.nextDouble() < exp((score - lastScore) / temperature)) { // accept
        lastScore = score;
        lastEnded = nowEnded;
      }
      else { // rollback
        swap(visitOrder[v1], visitOrder[v2]);
      }
    }
    else { // insert
      int v1 = theRandom.nextIntMod(totalOrderCount);
      int v2 = theRandom.nextIntMod(totalOrderCount);
      if (v1 == v2 || lastEnded < min(v1, v2)) continue;
      int tmp;
      tmp = visitOrder[v1];
      if (v1 < v2) {
        for (int i = v1; i < v2; i++) visitOrder[i] = visitOrder[i+1];
      }
      else {
        for (int i = v1; i > v2; i--) visitOrder[i] = visitOrder[i-1];
      }
      visitOrder[v2] = tmp;

      score = calcScore();

      #ifdef DEBUG
      if (iterCount % 10000 == 0) cerr << iterCount << " " << score << " " << lastScore << " " << bestScore << " " << temperature << endl;
      #endif

      if (score >= lastScore) {
        lastScore = score;
        if (score >= bestScore) {
          bestScore = score;
          bestVisitOrder = visitOrder;
        }
        lastEnded = nowEnded;
      }
      else if (theRandom.nextDouble() < exp((score - lastScore) / temperature)) { // accept
        lastScore = score;
        lastEnded = nowEnded;
      }
      else { // rollback
        tmp = visitOrder[v2];
        if (v2 < v1) {
          for (int i = v2; i < v1; i++) visitOrder[i] = visitOrder[i+1];
        }
        else {
          for (int i = v2; i > v1; i--) visitOrder[i] = visitOrder[i-1];
        }
        visitOrder[v1] = tmp;
      }
    }

    iterCount++;
    temperature *= 1.0 - decayRate;
  }

  visitOrder = bestVisitOrder;

  vector<int> ans = getAnswer();
  for (auto &x: ans) cout << x << endl;

  cerr << "iterCount   = " << iterCount << endl;
  cerr << "bestScore   = " << bestScore << endl;
  cerr << "temperature = " << temperature << endl;
  cerr << "timeTaken   = " << theTimer.time() << endl;

  return 0;
}


Measured memory_bytes: 19968