#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const double CPU_FREQ_ATCODER = 1.0 / (28 * 100 * 1000);
const double CPU_FREQ = CPU_FREQ_ATCODER;

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

class Timer
{
  long long start;
  long long cycle;

public:
  Timer() { start = rdtsc(); }
  void reset() { start = rdtsc(); }

  inline double elapsed()
  {
    cycle = rdtsc();
    return (cycle - start) * CPU_FREQ;
  }
};

inline double calcTemp(double startTime, double endTime, double curTime, double startTemp, double endTemp)
{
  const double c = 1 - (curTime - startTime) / (endTime - startTime);
  return c * (startTemp - endTemp) + endTemp;
}

class XorShiftL
{
  static const int LOG_CACHE_SIZE = 0x10000;

  int logIndex = 0;
  double logCache[LOG_CACHE_SIZE];

  std::uint64_t x = 88172645463325252LL;

public:
  XorShiftL()
  {
    for (int i = 0; i < LOG_CACHE_SIZE; i++) {
      logCache[i] = log((i + 0.5) / 0x10000);
    }
    shuffle(logCache);
  }

  std::uint64_t xor64()
  {
    x = x ^ (x << 7);
    return x = x ^ (x >> 9);
  }

  // [0, n)
  int nextInt(int n) { return xor64() % n; }

  // [low, high)
  int nextInt(int low, int high) { return xor64() % (high - low) + low; }
  double nextDouble() { return xor64() / double(std::numeric_limits<std::uint64_t>::max()); }

  /**
   * 2つの相異なる数をランダムに取得する
   * get<0>(result) < get<1>(result) が保証されている
   */
  std::tuple<int, int> nextIntPair(int low, int high)
  {
    int i = nextInt(low, high);
    int j = nextInt(low, high - 1);
    if (j >= i)
      j++;
    else
      std::swap(i, j);
    return std::make_tuple(i, j);
  }

  /**
   * 2つの相異なる数をランダムに取得する
   * get<0>(result) < get<1>(result) は保証されない
   */
  std::tuple<int, int> nextIntUnorderedPair(int low, int high)
  {
    int i = nextInt(low, high);
    int j = nextInt(low, high - 1);
    if (j >= i)
      j++;
    return std::make_tuple(i, j);
  }

  /**
   * ログを取得する
   */
  double nextLog()
  {
    const double res = logCache[logIndex++];
    if (logIndex == LOG_CACHE_SIZE) {
      logIndex = 0;
    }
    return res;
  }

  template <typename T>
  void shuffle(T &s)
  {
    for (int i = 1; i < (int)s.size(); i++) {
      int j = nextInt(0, i + 1);
      if (i != j) {
        std::swap(s[i], s[j]);
      }
    }
  }

  template <typename T, int n>
  void shuffle(T (&ary)[n])
  {
    for (int i = 1; i < n; i++) {
      int j = nextInt(0, i + 1);
      if (i != j) {
        std::swap(ary[i], ary[j]);
      }
    }
  }
};

class Seq
{
  struct OpHistory {
    int i, j;

    OpHistory() {}
    OpHistory(int i, int j) : i(i), j(j) {}
  };

  vector<int> seq;
  vector<OpHistory> history;

public:
  void push(int v)
  {
    seq.push_back(v);
  }

  vector<int>::iterator begin()
  {
    return seq.begin();
  }

  vector<int>::iterator end()
  {
    return seq.end();
  }

  int size() const
  {
    return seq.size();
  }

  void commit()
  {
    history.clear();
  }

  void rollback()
  {
    while (!history.empty()) {
      auto h = history.back();
      history.pop_back();
      std::swap(seq[h.i], seq[h.j]);
    }
  }

  void swap(int i, int j)
  {
    std::swap(seq[i], seq[j]);
    history.emplace_back(i, j);
  }

  int operator[](int i) const { return seq[i]; }
};

#ifdef PROFILE
#include <gperftools/profiler.h>
#endif

using namespace std;

struct Edge {
  int to, d;
  Edge() {}
  Edge(int to_, int d_) : to(to_), d(d_){};
};

struct Order {
  int64_t t;
  int id, dst;
  Order() {}
  Order(int t_, int id_, int dst_) : t(t_), id(id_), dst(dst_){};
  bool operator<(const Order &o) const { return t < o.t; }
};

int V, E;
vector<vector<Edge>> g;
vector<vector<int>> nxt;
vector<vector<int>> tim;
int64_t Tmax;
vector<Order> orders;
Timer timer;
XorShiftL rng;

template <typename T>
using pq = priority_queue<T, vector<T>, greater<T>>;

Seq state;
int64_t curCost = 1LL << 60;

vector<int> freq;
vector<bool> visited;
vector<int64_t> cnt;
vector<int64_t> sum1;
vector<int64_t> sum2;

void greedy()
{
  int uo = 0;
  int v = 0;
  int64_t t = 0;
  vector<Order> curOrders;

  int curState = 0;

  auto pick = [&]() {
    if (v != 0) return;
    for (; uo < (int)orders.size() && orders[uo].t <= t; uo++) {
      curOrders.push_back(orders[uo]);
      state.push(uo);
    }
  };

  auto step0 = [&](){
    if (curState != 0) return;
    t++;
    curState = 1;
    int n, id, dst;
    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> id >> dst;
      id--, dst--;
      orders.emplace_back(t, id, dst);
    }

    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> id;
      id--;
    }
    pick();
  };

  auto step1 = [&](){
    if (curState != 1) return;
    curState = 0;

    string verdict;
    cin >> verdict;

    int n, id;
    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> id;
      id--;
    }
  };

  auto moveTo = [&](int dst) {
    while (v != dst) {
      const int u = nxt[v][dst];
      for (int i = 0; i < tim[v][u]; i++) {
        step0();
        if (t > Tmax) return;
        cout << u + 1 << endl;
        step1();
      }
      v = u;
    }
  };

  auto stay = [&]() {
    step0();
    if (t > Tmax) return;
    cout << -1 << endl;
    step1();
  };

  cerr << t << " " << Tmax << endl;
  for (; t < Tmax;) {
    step0();

    if (curOrders.empty()) {
      moveTo(0);
      while (uo >= (int)orders.size() || t < orders[uo].t) {
        if (t > Tmax) break;
        stay();
      }
      continue;
    }

    int shortest = 0;
    for (int i = 1; i < (int)curOrders.size(); i++) {
      int d1 = curOrders[shortest].dst;
      int d2 = curOrders[i].dst;
      if (tim[v][d1] > tim[v][d2]) {
        shortest = i;
      }
    }

    moveTo(curOrders[shortest].dst);
    auto result = remove_if(curOrders.begin(), curOrders.end(),
                      [&](Order o) { return tim[v][o.dst] == 0; });
    curOrders.erase(result, curOrders.end());
  }

  // cerr << "greedy=" << cost << endl;
}

void solve()
{
  timer.reset();

  cin >> V >> E;
  g.resize(V);
  for (int i = 0; i < E; i++) {
    int u, v, d;
    cin >> u >> v >> d;
    u--, v--;
    g[u].emplace_back(v, d);
    g[v].emplace_back(u, d);
  }

  freq.resize(V);
  for (int i = 0; i < V; i++) {
    cin >> freq[i];
  }
  cin >> Tmax;
  // for (int i = 0; i < Tmax; i++) {
  //   int n, id, dst;
  //   cin >> n;
  //   for (int j = 0; j < n; j++) {
  //     cin >> id >> dst;
  //     id--, dst--;
  //     // if (i<= 292) cerr << i << " " << id << " " << dst << endl;
  //     orders.emplace_back(i, id, dst);
  //   }
  // }
  // cerr << V << " " << orders.size() << endl;

  cnt.resize(V);
  sum1.resize(V);
  sum2.resize(V);

  nxt.assign(V, vector<int>(V));
  tim.assign(V, vector<int>(V));
  for (int i = 0; i < V; i++) {
    pq<pair<int, int>> que;
    que.emplace(0, i);
    vector<pair<int, int>> dist(V, make_pair(1 << 29, -1));
    dist[i].first = 0;
    while (!que.empty()) {
      int v, d;
      tie(d, v) = que.top();
      que.pop();
      if (dist[v].first != d) continue;
      for (auto e : g[v]) {
        int c = d + e.d;
        if (dist[e.to].first <= c) continue;
        dist[e.to] = make_pair(c, v);
        que.emplace(c, e.to);
      }
    }
    for (int j = 0; j < V; j++) {
      if (i == j) {
        nxt[i][j] = -1;
        tim[i][j] = 0;
        continue;
      }
      int v;
      for (v = j; dist[v].second != i; v = dist[v].second) {
      }
      nxt[i][j] = v;
      tim[i][j] = dist[j].first;
    }
  }

  greedy();
}

int main()
{
#ifdef PROFILE
  ProfilerStart("");
#endif

  solve();

#ifdef PROFILE
  ProfilerStop();
#endif
}

Measured memory_bytes: 3412