#define LOCAL
#define DEBUG
#define _DEBUG2
#define _DEBUG3
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include "bits/stdc++.h"
#include <sys/time.h>
#include <emmintrin.h>
#include <string>
#include <bitset>

using namespace std;

inline long long GetTSC() {
  long long lo, hi;
  asm volatile ("rdtsc": "=a"(lo), "=d"(hi));
  return lo + (hi << 32);
}
inline double GetSeconds() {
  return GetTSC() / 2.8e9;
}

struct XorShift {
  uint64_t x = 88172645463325252ULL;
  double nl[65536];
  XorShift() {}

  void init(){
    double n2 = 1.0 / 65536*2;
    for(int i=0; i<65536; i++) nl[i] = log(i / 65536.0 + n2);
  }

  void setSeed(uint64_t seed) { x = seed; init(); }

  uint64_t next() {
    x ^= x << 13; x ^= x >> 7; x ^= x << 17;
    return x;
  }

  int nextInt(int n) {
    uint64_t upper = 0xFFFFFFFFFFFFFFFFULL / n * n;
    uint64_t v = next();
    while (v >= upper) v = next();
    return v % n;
  }

  double nextDouble() {
    uint64_t v = next() >> 11; // 53bit
    return (double)v / (1ULL << 53);
  }

  double nextLog() {
    return nl[nextInt(65536)];
  }
};


XorShift xs;
#ifdef LOCAL
const double TO = 29.8 * 1e-1;
#else
const double TO = 29.8;
#endif
const double TO1 = TO * 0.1;

double starttime, gt;
int ttt,ctt,dtt;

const int INF = 1e9;
const int VM = 400;
const int TM = 10000;
const int TM2 = TM * TM;
int V, E, IM;
int C[VM][VM];
int D[VM][VM];
vector<int> RT;
int F[VM];



void init(){
  cin >> V >> E;
  for(int i=0; i<V; i++) for(int j=0; j<V; j++) C[i][j] = INF;
  for(int i=0; i<E; i++){
    int u,v,d;
    cin >> u >> v >> d;
    u--; v--;
    C[u][v] = C[v][u] = d;
  }
  for(int i=0; i<V; i++) cin >> F[i];
  int t;
  cin >> t;

  // Warshall Floyd
  for(int i=0; i<V; i++) for(int j=0; j<V; j++) D[i][j] = C[i][j];
  for(int i=0; i<V; i++) D[i][i] = 0;
  for(int k=0; k<V; k++) for(int i=0; i<V; i++) for(int j=0; j<V; j++){
    D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
  }
}

void tsp(){
  RT.clear();
  int rc = 4;
  int rt = (V+rc-1) / rc;
  for(int i=1; i<V; i++){
    if(i%rt == 1) RT.emplace_back(0);
    RT.emplace_back(i);
  }
  RT.emplace_back(0);

  int N = RT.size();
  int sc = 0;
  for(int i=1; i<N; i++) sc += D[RT[i-1]][RT[i]];
  cerr << "ssc: " << sc << endl;

  ttt = ctt = 0;
  while(1){
    gt = GetSeconds() - starttime;
    if(gt >= TO1) break;
    int a = xs.nextInt(N-2) + 1;
    int b = xs.nextInt(N-2) + 1;
    if(RT[a] == 0 || RT[b] == 0 || a == b || abs(a-b) < 2) continue;
    ttt++;

    int cc = D[RT[a]][RT[a-1]] + D[RT[a]][RT[a+1]] + D[RT[b]][RT[b-1]] + D[RT[b]][RT[b+1]];
    int nc = D[RT[a]][RT[b-1]] + D[RT[a]][RT[b+1]] + D[RT[b]][RT[a-1]] + D[RT[b]][RT[a+1]];
    if(cc >= nc){
      sc += nc;
      sc -= cc;
      swap(RT[a], RT[b]);
      ctt++;
    }
  }

  cerr << "esc: " << sc << endl;
}

void solve(){
  tsp();

  vector<tuple<int, int>> rt;
  for(int i=0; i<RT.size()-1; i++){
    int c = RT[i];
    int t = RT[i+1];
    int d = D[c][t];
    while(C[c][t] == INF){
      for(int n=0; n<V; n++){
        if(n == c || n == t) continue;
        if(C[c][n] == INF || C[c][n] < 1) continue;
        if(C[c][n] + D[n][t] == d){
          rt.emplace_back(n, C[c][n]);
          d -= C[c][n];
          c = n;
          break;
        }
      }
    }
    rt.emplace_back(t, C[c][t]);
  }

  int t = 0;
  while(t < TM){
    for(auto r : rt){
      int n = get<0>(r);
      int rc = get<1>(r);
      for(int i=0; i<rc && t<TM; i++, t++){
        int nn,nid,dst;
        cin >> nn;
        for(int j=0; j<nn; j++) cin >> nid >> dst;

        int np,pid;
        cin >> np;
        for(int j=0; j<np; j++) cin >> pid;

        cout << n+1 << endl;
        string s;
        cin >> s;
        if(s == "NG") return;

        int na,aid;
        cin >> na;
        for(int j=0; j<na; j++) cin >> aid;
      }
    }
  }

  cerr << "time: " << (GetSeconds() - starttime);
  cerr << " ttt: " << ttt << " ctt: " << ctt << " dtt: " << dtt << endl;
}

void output(){
}

int main() {
  starttime = GetSeconds();
  srand((unsigned) time(NULL));
  xs.setSeed(rand() % 65536 + 65537);
  init();
  solve();
  output();

  return 0;
}



Measured memory_bytes: 3028