#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
template <typename T>
struct WarshallFloyd {
  vector<vector<T> > graph, dist;

  WarshallFloyd(const vector<vector<T> > &graph, T TINF) : graph(graph), TINF(TINF) {
    n = graph.size();
    dist = graph;
    internal.assign(n, vector<int>(n, -1));
    REP(k, n) REP(i, n) REP(j, n) {
      if (dist[i][k] != TINF && dist[k][j] != TINF && dist[i][j] > dist[i][k] + dist[k][j]) {
        dist[i][j] = dist[i][k] + dist[k][j];
        internal[i][j] = k;
      }
    }
  }

  void add(int src, int dst, T cost) {
    srcs.emplace_back(src);
    dsts.emplace_back(dst);
    costs.emplace_back(cost);
  }

  void calc() {
    set<int> ver;
    int sz = srcs.size();
    REP(i, sz) {
      int s = srcs[i], t = dsts[i];
      T cost = costs[i];
      graph[s][t] = min(graph[s][t], cost);
      if (dist[s][t] >= cost) {
        dist[s][t] = cost;
        internal[s][t] = -1;
      }
      ver.insert(s);
      ver.insert(t);
    }
    for (int v : ver) {
      REP(i, n) REP(j, n) {
        if (dist[i][v] != TINF && dist[v][j] != TINF && dist[i][j] > dist[i][v] + dist[v][j]) {
          dist[i][j] = dist[i][v] + dist[v][j];
          internal[i][j] = v;
        }
      }
    }
    srcs.clear();
    dsts.clear();
    costs.clear();
  }

  bool has_negative_cycle() {
    REP(i, n) if (dist[i][i] < 0) return true;
    return false;
  }

  vector<int> build_path(int s, int t) {
    vector<int> res;
    if (dist[s][t] != TINF) {
      build_path(s, t, res);
      res.emplace_back(t);
    }
    return res;
  }

private:
  const T TINF;
  int n;
  vector<vector<int> > internal;
  vector<int> srcs, dsts;
  vector<T> costs;

  void build_path(int s, int t, vector<int> &path) {
    int k = internal[s][t];
    if (k == -1) path.emplace_back(s);
    else {
      build_path(s, k, path);
      build_path(k, t, path);
    }
  }
};

void ok() {
  string verdict; cin >> verdict;
  if (verdict == "NG") assert(false);
  int n_achieve; cin >> n_achieve;
  while (n_achieve--) {
    int achieve_id; cin >> achieve_id;
  }
}

int main() {
  int v, e; cin >> v >> e;
  vector<vector<int> > graph(v, vector<int>(v, INF));
  while (e--) {
    int u, v, d; cin >> u >> v >> d; --u; --v;
    graph[u][v] = graph[v][u] = d;
  }
  WarshallFloyd<int> wf(graph, INF);
  vector<int> f(v); REP(i, v) cin >> f[i];
  int t; cin >> t;
  int pos = 0, dst = -1, idx, journey;
  vector<vector<vector<int> > > path(v, vector<vector<int> >(v));
  set<int> goods, load;
  REP(i, t) {
    int n_new; cin >> n_new;
    if (n_new == 1) {
      int new_id, dst; cin >> new_id >> dst; --dst;
      goods.emplace(dst);
    }
    int n_put; cin >> n_put;
    while (n_put--) {
      int put_id; cin >> put_id;
    }
    // cout << i << ':' << pos << ' ' << dst << ' ' << idx << ' ' << journey << endl;
    if (dst == -1) {
      for (int e : goods) load.emplace(e);
      goods.clear();
      if (load.empty()) {
        cout << -1 << endl;
        ok();
        continue;
      }
      int dist = INF;
      for (int e : load) {
        if (wf.dist[pos][e] < dist) {
          dst = e;
          dist = wf.dist[pos][e];
        }
      }
      if (path[pos][dst].empty()) path[pos][dst] = wf.build_path(pos, dst);
      idx = 1;
      journey = wf.dist[pos][path[pos][dst][idx]] - 1;
      cout << path[pos][dst][idx] + 1 << endl;
    } else {
      if (journey == 0) {
        if (path[pos][dst][idx] == 0) {
          for (int e : goods) load.emplace(e);
          goods.clear();
        }
        ++idx;
        if (idx == path[pos][dst].size()) {
          pos = dst;
          if (pos == 0) {
            dst = -1;
            if (load.empty()) {
              cout << -1 << endl;
              ok();
              continue;
            }
            int dist = INF;
            for (int e : load) {
              if (wf.dist[pos][e] < dist) {
                dst = e;
                dist = wf.dist[pos][e];
              }
            }
            if (path[pos][dst].empty()) path[pos][dst] = wf.build_path(pos, dst);
            idx = 1;
            journey = wf.dist[pos][path[pos][dst][idx]] - 1;
            cout << path[pos][dst][idx] + 1 << endl;
          } else {
            load.erase(dst);
            dst = -1;
            if (load.empty()) {
              dst = 0;
            } else {
              int dist = INF;
              for (int e : load) {
                if (wf.dist[pos][e] < dist) {
                  dst = e;
                  dist = wf.dist[pos][e];
                }
              }
            }
            if (path[pos][dst].empty()) path[pos][dst] = wf.build_path(pos, dst);
            idx = 1;
            journey = wf.dist[pos][path[pos][dst][idx]] - 1;
            cout << path[pos][dst][idx] + 1 << endl;
          }
        } else {
          journey = wf.dist[path[pos][dst][idx - 1]][path[pos][dst][idx]] - 1;
          cout << path[pos][dst][idx] + 1 << endl;
        }
      } else {
        cout << path[pos][dst][idx] + 1 << endl;
        --journey;
      }
    }
    ok();
  }
  return 0;
}


Measured memory_bytes: 9552