#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 = 11111;
constexpr int MAX_V = 444;
constexpr int MAX_E = MAX_V * 2;
int V, E, T;
int F[MAX_V];
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];
  }
}

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]];
  if (false) {
    constexpr int LOOP = 0xffffff;
    for (int q = LOOP; q && dist > limit; --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) {
        dist -= now - nxt;
        for (int l = i, r = b; l < r; ++l, --r) swap(v[l], v[r]);
      }
    }
    return v;
  } else {
    vector<int> best = v;
    int a = 0, bestScore = dist;
    static int penalty[MAX_V][MAX_V];
    for (int i = 0; i <= V; ++i) {
      for (int j = 0; j <= V; ++j) {
        penalty[i][j] = 1;
      }
    }
    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 < 0x2ffff && bestScore > limit; ++q) {
      {
        int b = (a + 1) % n;
        for (int c = 0; c < n; ++c) {
          if (a == c) continue;
          int d = (c + 1) % n;
          int now = D(a, b) + D(c, d);
          int nxt = D(a, c) + D(b, d);
          int deltaScore = nxt - now;
          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());
            }
          }
        }
      }
      double maxUtil = 0;
      for (int i = 0; i < n; ++i) {
        int j = (i + 1) % n;
        double util = (double)D(i, j) / P(i, j);
        if (maxUtil < util) {
          maxUtil = util;
          a = i;
        }
      }
      {
        int b = (a + 1) % n;
        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);
        }
      }
    }
    for (int i = 0; i < V; ++i) {
      cin >> F[i];
    }
    cin >> T;
  }
  {  // solve
    set<int> dst;
    for (int t = 0; t < T; ++t) {
      {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
          int id, d;
          cin >> id >> d;
          DST[id] = d;
        }
        cin >> n;
        for (int i = 0; i < n; ++i) {
          int id;
          cin >> id;
          dst.insert(DST[id]);
        }
      }
      if (dst.size() > 0) {
        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();
      }
      {
        string s;
        cin >> s;
        assert(s == "OK");
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
          int achieve;
          cin >> achieve;
        }
      }
    }
  }
}


Measured memory_bytes: 3652