#include <bits/stdc++.h>

using namespace std;
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 29)

using Pi = pair<int, int>;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}
using Ppi = pair<int, pair<int, int>>;

int V, E, T;
vector<vector<Pi>> G;
vector<vector<int>> orders;
vector<vector<int>> dists;
vector<vector<vector<Ppi>>> pathes;

void find_pathes() {
  vector<vector<int>> prev(V, vector<int>(V));
  FOR(i, V) {
    dists[i][i] = 0;
    FOR(j, V) { prev[i][j] = i; }
  }
  FOR(k, V) {
    FOR(i, V) {
      FOR(j, V) {
        if (dists[i][k] + dists[k][j] < dists[i][j]) {
          dists[i][j] = dists[i][k] + dists[k][j];
          prev[i][j] = prev[k][j];
        }
      }
    }
  }
  FOR(s, V) {
    FOR(g, V) {
      int now = g;
      while (now != s) {
        int pr = prev[s][now];
        pathes[s][g].push_back(Ppi(dists[s][now] - dists[s][pr], Pi(pr, now)));
        now = pr;
      }
    }
  }
}

int main() {
  cin >> V >> E;
  G.resize(V);
  dists = vector<vector<int>>(V, vector<int>(V, INF));
  pathes.resize(V);
  FOR(i, V) { pathes[i].resize(V); }
  FOR(i, E) {
    int u, v, d;
    cin >> u >> v >> d;
    u--;
    v--;
    G[u].emplace_back(d, v);
    G[v].emplace_back(d, u);
    dists[u][v] = d;
    dists[v][u] = d;
  }
  vector<double> f(V);
  FOR(i, V) cin >> f[i];
  double sum = accumulate(ALL(f), 0.0);
  FOR(i, V) f[i] /= sum;
  find_pathes();
  cin >> T;
  orders.resize(T);
  int now = 0;
  int next = 0;
  vector<int> wait;
  unordered_set<int> can;
  vector<int> actions(T * 10, -1);
  FOR(i, T) {
    int Nnew;
    cin >> Nnew;
    FOR(j, Nnew) {
      int new_id, dst;
      cin >> new_id >> dst;
      wait.push_back(dst - 1);
    }
    if (now == i) {
      if (next == 0) {
        for (int v : wait) {
          can.insert(v);
        }
        wait.clear();
      }
      int min_dest = 0, min_d = dists[next][0] + 1;
      if (wait.size() < 5) min_d = INF;
      if (!can.empty()) {
        for (int v : can) {
          if (min_d >= dists[next][v]) {
            min_d = dists[next][v];
            min_dest = v;
          }
        }
        can.erase(min_dest);
        vector<Ppi> path = pathes[next][min_dest];
        for (int a = path.size() - 1; a >= 0; --a) {
          FOR(b, path[a].first) { actions[now++] = path[a].second.second + 1; }
        }
        next = min_dest;
      } else {
        if (next == 0) {
          now++;
        } else {
          int g = 0;
          vector<Ppi> path = pathes[next][0];
          for (int a = path.size() - 1; a >= 0; --a) {
            FOR(b, path[a].first) {
              actions[now++] = path[a].second.second + 1;
            }
          }
          next = 0;
        }
      }
    }
    int Nput;
    cin >> Nput;
    vector<int> put_id(Nput);
    FOR(j, Nput) cin >> put_id[j];
    cout << actions[i] << endl;
    string verdict;
    cin >> verdict;
    int Nachieve;
    cin >> Nachieve;
    vector<int> achieve_id(Nachieve);
    FOR(j, Nachieve) cin >> achieve_id[j];
  }
  return 0;
}

Measured memory_bytes: 49360