#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];
queue<int> command;

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) command.push(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 = d, r = a; 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 best;
}

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;
  }
  {  // solve
    set<int> dst;
    for (int t = 0; t < T; ++t) {
      {
        int n;
        cin >> n;
        for (int j = 0; j < n; ++j) {
          int id, d;
          cin >> id >> d;
          dst.insert(d);
        }
      }
      if (command.empty() && dst.size()) {
        vector<int> route = TSP(dst);
        dst.clear();
        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]);
        }
      }
      if (command.empty()) {
        cout << -1 << endl;
      } else {
        cout << command.front() << endl;
        command.pop();
      }
    }
  }
  // debug(timer.getElapsed());
}


Measured memory_bytes: 3320