#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 MAX_T = 10000;
int V, E, T = 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];
  }
}

vector<int> TSP(set<int>& dst) {
  dst.insert(1);
  vector<int> v(dst.begin(), dst.end());
  int n = v.size(), d = 0;
  for (int i = 0; i < n; ++i) d += DIST[v[i]][v[(i + 1) % n]];
  constexpr int LOOP = 0xffffff;
  for (int q = LOOP; q; --q) {
    int a = get_random(n);
    int b = get_random(n);
    if (a == b) continue;
    if (a > b) swap(a, b);
    int i = (a + 1) % n;
    int j = (b + 1) % n;
    int now = DIST[v[a]][v[i]] + DIST[v[b]][v[j]];
    int nxt = DIST[v[a]][v[b]] + DIST[v[i]][v[j]];
    if (now - nxt > get_random_log() * q / LOOP) {
      d -= now - nxt;
      for (int k = 0; k * 2 < (b + 1 - i); ++k) {
        swap(v[i + k], v[b - k]);
      }
    }
  }
  {  // test
    int test = 0;
    for (int i = 0; i < n; ++i) test += DIST[v[i]][v[(i + 1) % n]];
    assert(d == test);
  }
  debug(n, d);
  return v;
}

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 >> MAX_T;
    for (int i = 0; i < MAX_T; ++i) {
      int n;
      cin >> n;
      for (int j = 0; j < n; ++j) {
        int id, dst;
        cin >> id >> dst;
        TIME[T] = i;
        DST[T] = dst;
        T++;
      }
    }
  }
  {  // solve
    set<int> dst;
    for (int t = 0; t < T;) {
      while (true) {
        for (; t < T && TIME[t] <= OUTPUT.size(); ++t) dst.insert(DST[t]);
        if (dst.size() > 0) {
          break;
        } else {
          OUTPUT.push_back(-1);
        }
      }
      vector<int> route = TSP(dst);
      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() < MAX_T) OUTPUT.push_back(-1);
    for (int i = 0; i < MAX_T; ++i) cout << OUTPUT[i] << endl;
  }
}


Measured memory_bytes: 2176