#include <sys/time.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(char c) {
  string res = "";
  res += c;
  return res;
}

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

string to_string(uint8_t v) { return to_string((int)v); }
string to_string(uint16_t v) { return to_string((int)v); }

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

class Timer {
 public:
  void restart();
  double getElapsed();

  Timer();

 private:
  static double rdtsc_per_sec_inv;

  double getTimeOfDay();
  unsigned long long int getCycle();

  double start_time;
  unsigned long long int start_clock;
};
double Timer::rdtsc_per_sec_inv = -1;

inline double Timer::getElapsed() {
  if (rdtsc_per_sec_inv != -1)
    return (double)(getCycle() - start_clock) * rdtsc_per_sec_inv;

  const double RDTSC_MEASUREMENT_INTERVAL = 0.1;
  double res = getTimeOfDay() - start_time;
  if (res <= RDTSC_MEASUREMENT_INTERVAL) return res;

  rdtsc_per_sec_inv = 1.0 / (getCycle() - start_clock);
  rdtsc_per_sec_inv *= getTimeOfDay() - start_time;
  return getElapsed();
}

inline void Timer::restart() {
  start_time = getTimeOfDay();
  start_clock = getCycle();
}

Timer::Timer() { restart(); }

inline double Timer::getTimeOfDay() {
  timeval tv;
  gettimeofday(&tv, 0);
  return tv.tv_sec + tv.tv_usec * 0.000001;
}

inline unsigned long long int Timer::getCycle() {
  unsigned int low, high;
  __asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
  return ((unsigned long long int)low) | ((unsigned long long int)high << 32);
}

inline unsigned get_random() {
  static unsigned y = 2463534242;
  return y ^= (y ^= (y ^= y << 13) >> 17) << 5;
}
inline double get_random_double() { return (double)get_random() / UINT32_MAX; }
inline unsigned get_random(int x) { return get_random() % x; }
inline double get_random_log() { return log(get_random_double()); }

Timer timer;
constexpr int MAX_T = 10000;
constexpr int MAX_V = 444;
constexpr int MAX_E = MAX_V * 2;
int V, E, T, O = 0;
int DIST[MAX_V][MAX_V];
vector<int> edge[MAX_V];
int TIME[MAX_T];
int DST[MAX_T];
vector<int> OUTPUT;

void move(int p, int dst) {
  int d = DIST[p][dst];
  while (p != dst) {
    int n = -1;
    for (int i : edge[p]) {
      if (d == DIST[p][i] + DIST[i][dst]) n = i;
    }
    assert(n != -1);
    for (int i = 0; i < DIST[p][n]; ++i) OUTPUT.push_back(n);
    p = n;
    d = DIST[p][dst];
  }
}

set<int> moveSet(int p, int dst) {
  int d = DIST[p][dst];
  set<int> set{p};
  while (p != dst) {
    int n = -1;
    for (int i : edge[p]) {
      if (d == DIST[p][i] + DIST[i][dst]) n = i;
    }
    assert(n != -1);
    p = n;
    d = DIST[p][dst];
    set.insert(p);
  }
  return set;
}

auto TSP(set<int>& dst, int limit = 0) {
  dst.insert(1);
  vector<int> v(dst.begin(), dst.end());
  int n = v.size(), dist = 0;
  for (int i = 0; i < n; ++i) dist += DIST[v[i]][v[(i + 1) % n]];
  vector<int> best = v;
  int a = 0, bestScore = dist;
  static int penalty[MAX_V][MAX_V];
  memset(penalty, 0, sizeof(penalty));
  auto D = [&](int i, int j) { return DIST[v[i]][v[j]]; };
  auto P = [&](int i, int j) { return penalty[v[i]][v[j]]; };
  for (int q = 0; q < n * n && bestScore > limit; ++q) {
    int b = (a + 1) % n;
    for (int c = 0; c < n; ++c) {
      int d = (c + 1) % n;
      if (c == a || c == b || d == a || d == b) continue;
      int deltaScore = (D(a, c) + D(b, d)) - (D(a, b) + D(c, d));
      int deltaPenalty = bestScore * (P(a, b) + P(c, d) - P(a, c) - P(b, d));
      if (deltaScore * n < deltaPenalty) {
        dist += deltaScore;
        if (b <= c) {
          for (int l = b, r = c; l < r; l++, r--) swap(v[l], v[r]);
        } else {
          for (int l = c + 1, r = b - 1; l < r; l++, r--) swap(v[l], v[r]);
        }
        if (bestScore > dist) {
          bestScore = dist;
          copy(v.begin(), v.end(), best.begin());
        }
      }
    }
    int d = D(a, b), p = P(a, b);
    for (int i = 0; i < n; ++i) {
      int j = (i + 1) % n, d_ = D(i, j), p_ = P(i, j);
      if (d * p_ < d_ * p) a = i, b = j, d = d_, p = p_;
    }
    penalty[v[a]][v[b]]++;
    penalty[v[b]][v[a]]++;
  }
  return make_tuple(best, bestScore);
}

int main() {
  {  // input
    cin >> V >> E;
    memset(DIST, 0xf, sizeof(DIST));
    for (int i = 0; i < E; ++i) {
      int u, v, d;
      cin >> u >> v >> d;
      DIST[u][v] = DIST[v][u] = d;
    }
    int PREV[MAX_V][MAX_V];
    memcpy(PREV, DIST, sizeof(DIST));
    for (int i = 1; i <= V; ++i) DIST[i][i] = 0;
    for (int k = 0; k <= V; ++k) {
      for (int i = 0; i <= V; ++i) {
        for (int j = 0; j <= V; ++j) {
          int d = DIST[i][k] + DIST[k][j];
          if (DIST[i][j] > d) DIST[i][j] = d;
        }
      }
    }
    for (int i = 1; i <= V; ++i) {
      for (int j = i + 1; j <= V; ++j) {
        if (PREV[i][j] == DIST[i][j]) {
          edge[i].push_back(j);
          edge[j].push_back(i);
        }
      }
    }
    cin >> T;
    for (int i = 0; i < T; ++i) {
      int n;
      cin >> n;
      for (int j = 0; j < n; ++j) {
        int id, dst;
        cin >> id >> dst;
        TIME[O] = i;
        DST[O] = dst;
        O++;
      }
    }
  }
  {  // solve
    vector<tuple<vector<int>, int>> routes;
    auto solve = [&](int O) {
      set<int> dst, used;
      vector<int> route;
      vector<tuple<vector<int>, int>> result;
      for (int o = O, t0 = T, t1 = TIME[o];; --o) {
        int t = TIME[o], d = DST[o];
        if (used.find(d) == used.end() && dst.find(d) == dst.end()) {
          dst.insert(d);
          int dist, limit = t0 - t1;
          vector<int> r;
          tie(r, dist) = TSP(dst, limit);
          if (dist > limit) {
            if (route.empty()) return false;
            result.push_back(make_tuple(route, t1));
            for (int i = 0; i < route.size(); ++i) {
              set<int> set = moveSet(route[i], route[(i + 1) % route.size()]);
              used.insert(set.begin(), set.end());
            }
            route.clear();
            t0 = t1;
            t1 = t;
            dst.clear();
            dst.insert(d);
          } else {
            route = r;
          }
        }
        if (o == 0) {
          if (route.size()) result.push_back(make_tuple(route, t1));
          routes = result;
          return true;
        }
      }
    };
    int min = O - 1000, max = O;
    while (max - min > 1) {
      int x = (max + min) / 2;
      if (solve(x)) {
        min = x;
      } else {
        max = x;
      }
    }
    {
      set<int> dst;
      for (int i = 1; i <= V; ++i) dst.insert(i);
      vector<int> route;
      int dist, time = get<1>(routes.back());
      tie(route, dist) = TSP(dst);
      while (dist <= time) {
        time -= dist;
        routes.push_back(make_tuple(route, time));
      }
    }
    reverse(routes.begin(), routes.end());
    for (auto x : routes) {
      vector<int> route;
      int t;
      tie(route, t) = x;
      while (OUTPUT.size() < t) OUTPUT.push_back(-1);
      int n = route.size(), p = -1;
      for (int i = 0; i < n; ++i)
        if (route[i] == 1) p = i;
      assert(p != -1);
      for (int i = 0; i < n; ++i) {
        move(route[(p + i) % n], route[(p + i + 1) % n]);
      }
    }
  }
  {  // output
    while (OUTPUT.size() < T) OUTPUT.push_back(-1);
    for (int i = 0; i < T; ++i) cout << OUTPUT[i] << endl;
  }
  // debug(timer.getElapsed());
}


Measured memory_bytes: 2944