#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <cassert>
using namespace std;

vector <pair <int, int> > edges[400];
int d[400][400];
int new_ids[100000];
int dsts[10000];
bool done[10000];
int f[400];

int V;
int E;
int T_max;
int order_no;
int put_no;
enum State {
  STAY = 1,
  DELIVER = 2,
  RETURN = 3
};

void initialize_d(){
  for(int i = 0; i < V; i++){
    for(int j = 0; j < V; j++){
        if(i == j){
            d[i][j] = 0;
        } else {
            d[i][j] = -1;
        }

    }
  }
}

void initialize_edges(){
  for(int i = 0; i < E; i++){
    int u;
    int v;
    int d_uv;
    cin >> u >> v >> d_uv;
    edges[u - 1].push_back(make_pair(v - 1, d_uv));
    edges[v - 1].push_back(make_pair(u - 1, d_uv));
    d[u - 1][v - 1] = d_uv;
    d[v - 1][u - 1] = d_uv;
  }
}

void process_new_orders(){
    int N_new;
    cin >> N_new;
    for(int i = 0; i < N_new; i++){
        int id;
        int dst_new;
        cin >> id >> dst_new;
        dsts[order_no] = dst_new - 1;
        order_no ++;
    }
    int N_put;
    cin >> N_put;
    for(int i = 0; i < N_put; i++){
        int id;
        cin >> id;
        put_no ++;
    }
}

void process_judge_output(){
    string verdict;
    cin >> verdict;
    assert(verdict == "OK");
    
    int N_ach;
    cin >> N_ach;
    for(int i = 0; i < N_ach; i++){
        int id;
        cin >> id;
        done[id - 1] = true;
    }

}

void apsp(){
  for(int k = 0; k < V; k++){
        for(int i = 0; i < V; i++){
            for(int  j = 0; j < V; j++){
                if(d[i][k] != -1 && d[k][j] != -1){
                    if(d[i][j] != -1){
                        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                    } else {
                        d[i][j] = d[i][k] + d[k][j];
                    }
                }
            }
        }
    }
}

//env update
void adjust_pos(int &cur_pos, int &dst_to_next, int &next_pos){
  if(dst_to_next == 0){
    cur_pos = next_pos;
    dst_to_next = -1;
    next_pos = -1;
  }
}

void update_delivered(int cur_pos, 
    int dst_to_next, int next_pos, int &delivered_i){
  if(dst_to_next < 0){
    while(dsts[delivered_i] == cur_pos || done[cur_pos]){
      delivered_i ++;
    }
  }
}

//state update
void update_state_stay(int cur_pos, int dst_to_next, 
    int next_pos, int delivered_i, State & state){
    if(delivered_i < put_no){
      state = DELIVER;
    }
}

void update_state_deliver(int cur_pos, int dst_to_next, 
    int next_pos, int delivered_i, State & state){
  if(delivered_i == put_no){
    if(cur_pos != 0 || dst_to_next >= 0){
      state = RETURN;
    } else {
      state = STAY;
    }
  }
}

void update_state_return(int cur_pos, int dst_to_next, 
    int next_pos, int delivered_i, State & state){
  if(cur_pos == 0 && dst_to_next < 0){
    state = STAY;
  }
}

void update_state(int cur_pos, int dst_to_next, 
    int next_pos, int delivered_i, State & state){
  if(state==STAY){
    update_state_stay(cur_pos, dst_to_next, next_pos, delivered_i, state);
  } else if(state == DELIVER){
    update_state_deliver(cur_pos, dst_to_next, next_pos, delivered_i, state);
  } else {
    update_state_return(cur_pos, dst_to_next, next_pos, delivered_i, state);
  }
}

//actions
void move_to(int &cur_pos, int &dst_to_next, int &next_pos, int &deliverd_i, 
    State &state, int final_dst){
  assert(dst_to_next != 0);
  if(dst_to_next > 0){
    cout << next_pos + 1 << endl;
    dst_to_next --;
  } else {
    for(int i = 0; i < edges[cur_pos].size(); i++){
      int next = edges[cur_pos][i].first;
      int next_dst = edges[cur_pos][i].second;
      //cout << "move_to, next: " << next << " " << next_dst << " " << d[next][final_dst] << " " << d[cur_pos][final_dst] << endl;

      if(next_dst + d[next][final_dst] == d[cur_pos][final_dst]){
        dst_to_next = next_dst - 1;
        next_pos = next;
        cout << next_pos + 1 << endl;
        break;
      }
    }
  }
}

void action_stay(int &cur_pos, int &dst_to_next, 
    int &next_pos, int &delivered_i, State &state){
  cout << -1 << endl;
}

void action_deliver(int &cur_pos, int &dst_to_next, 
    int &next_pos, int &delivered_i, State &state){
  move_to(cur_pos, dst_to_next, next_pos, delivered_i, state, dsts[delivered_i]);
}

void action_return(int &cur_pos, int &dst_to_next, 
    int &next_pos, int &delivered_i, State &state){
  move_to(cur_pos, dst_to_next, next_pos, delivered_i, state, 0);
}

void action(int &cur_pos, int &dst_to_next, 
    int &next_pos, int &delivered_i, State &state){
  if(state == STAY){
    action_stay(cur_pos, dst_to_next, next_pos, delivered_i, state);
  } else if(state == DELIVER){
    action_deliver(cur_pos, dst_to_next, next_pos, delivered_i,  state);
  } else {
    action_return(cur_pos, dst_to_next, next_pos, delivered_i, state);
  }
}


int main(){
  cin >> V >> E;

  initialize_d();
  initialize_edges();

  for(int i = 0; i < V; i++){
      cin >> f[i];
  }
  cin >> T_max;
  
  apsp();

  int delivered_i = 0;
  int cur_pos = 0;
  int dst_to_next = -1;
  int next_pos = -1;
  State state = STAY;
  for(int t = 0; t < T_max; t++){
    process_new_orders();
    adjust_pos(cur_pos, dst_to_next, next_pos);
    update_delivered(cur_pos, dst_to_next, next_pos, delivered_i);
    update_state(cur_pos, dst_to_next, next_pos, delivered_i, state);
    //cout << t << " "  << state << " " << cur_pos << " " << dst_to_next << " " << dsts[delivered_i] << endl;
    action(cur_pos, dst_to_next, next_pos, delivered_i, state);
    process_judge_output();
  }
  return 0;
}


Measured memory_bytes: 2132