#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[100000];
int revealed[100000];

int V;
int E;
int T_max;
int order_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 initialize_orders(){
  for(int i = 0; i < T_max; i++){
    int N_new;
    cin >> N_new;
    if(N_new > 0){
      for(int i = 0; i < N_new; i++){
        int new_id;
        int dst;
        cin >> new_id >> dst;
        new_ids[order_no] = new_id;
        dsts[order_no] = dst - 1;
        order_no++;
      }
    }
    revealed[i] = order_no;
  }
}

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){
      delivered_i ++;
    }
  }
}

void update_picked_up(int cur_pos, 
    int dst_to_next, int next_pos, int t, int &picked_up_i){
  if(cur_pos == 0 && dst_to_next < 0){
    picked_up_i = revealed[t];
  }
}

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

void update_state_deliver(int cur_pos, int dst_to_next, 
    int next_pos, int delivered_i, int picked_up_i, State & state){
  if(delivered_i == picked_up_i){
    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, int picked_up_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, int picked_up_i, State & state){
  if(state==STAY){
    update_state_stay(cur_pos, dst_to_next, next_pos, delivered_i, picked_up_i, state);
  } else if(state == DELIVER){
    update_state_deliver(cur_pos, dst_to_next, next_pos, delivered_i, picked_up_i, state);
  } else {
    update_state_return(cur_pos, dst_to_next, next_pos, delivered_i, picked_up_i, state);
  }
}

//actions
void move_to(int &cur_pos, int &dst_to_next, int &next_pos, int &deliverd_i, 
    int &picked_up_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;
      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, int &picked_up_i, State &state){
  cout << -1 << endl;
}

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

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

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


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

  initialize_d();
  initialize_edges();

  cin >> T_max;
  initialize_orders();

  apsp();

  int delivered_i = 0;
  int picked_up_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++){
    adjust_pos(cur_pos, dst_to_next, next_pos);
    update_delivered(cur_pos, dst_to_next, next_pos, delivered_i);
    update_picked_up(cur_pos, dst_to_next, next_pos, t, picked_up_i);
    update_state(cur_pos, dst_to_next, next_pos, delivered_i, picked_up_i, state);
    //cout << t << " "  << state << " " << cur_pos << " " << dst_to_next << " " << dsts[delivered_i] << endl;
    action(cur_pos, dst_to_next, next_pos, delivered_i, picked_up_i, state);
  }
  return 0;
}


Measured memory_bytes: 1024