#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

struct road {
  int to, cost;
};

struct M {
  int cost, from;
  vector<int> route;
};

bool operator>(const M& m1, const M& m2) {
  if (m1.cost == m2.cost) {
    return m1.from < m2.from;
  } else {
    return m1.cost < m2.cost;
  }
}

int main() {
  int v, e; cin >> v >> e;
  vector<road> r[v];
  
  for(int i=0; i<e; i++) {
    int a, b, c;
    cin >> a >> b >> c; a--; b--;
    r[a].push_back({b,c});
    r[b].push_back({a,c});
  }
  
  int fs[v][v]; fill(fs[0], fs[v], 1e9);
  vector<int> fs_route[v][v];
  for(int i=0; i<v; i++) {
    priority_queue<M, vector<M>, greater<M>> q;
    fs[i][i] = 0;
    
    q.push({0,i});
    
    while(!q.empty()) {
      M p = q.top(); q.pop();
      int cost = p.cost, from = p.from;
      if (fs[i][from] < cost) continue;
      for(road x:r[from]) {
        if (fs[i][x.to] > fs[i][from] + x.cost) {
          fs[i][x.to] = fs[i][from] + x.cost;
          
          vector<int> x_route = p.route; x_route.push_back(x.to);
          fs_route[i][x.to] = x_route;
            
          q.push({fs[i][x.to], x.to, x_route});
        }
      }
    }
  }
  
  int Tmax; cin >> Tmax;
  int tm[Tmax]; fill(tm, tm+Tmax, -1);
  int n;
  
  for(int i=0; i<Tmax; i++) {
    int _; cin >> n;
    if (n) {cin >> _ >> tm[i]; tm[i]--;}
  }
  
  /*
  
  for(int time = 0; time < Tmax; time ++) {
    int nww; cin >> nww; if (nww) {int new_one; cin >> new_one;}
    int npu; cin >> npu; for(int i=0; i<npu; i++)  ccccccc;
    
  }
  
  */
  
  int tasks_queue[v], tasks_ongoing[v];
  fill(tasks_queue, tasks_queue+v, 0); fill(tasks_ongoing, tasks_ongoing+v, 0); 
  queue<int> going_place;
  
  int nw = 0, nx = 0, remain = 0;
  //cout << "Hi" << endl;
  
  for(int time=0; time < Tmax; time++) {
    //cout << "&" << time << ": " << remain << ", " << nw << ", " << nx << ", " << finiced_task << ", " << happened_task << " ";
    tasks_queue[tm[time]]++;
    if (nw == 0 && remain == 0) {
      //cout << "z";
      for(int i=0; i<v; i++) {
        tasks_ongoing[i] += tasks_queue[i]; tasks_queue[i] = 0;
      }
      int mn = 1e9, id = -1;
      for(int i=0; i<v; i++) {
        if (tasks_ongoing[i] > 0 && mn > fs[0][i] / tasks_ongoing[i]) {
          mn = fs[0][i] / tasks_ongoing[i]; id = i;
        }
      }
      if (id == -1) {puts("-1"); continue;}
      //cout << "(";
      for(int x:fs_route[0][id]) {
        going_place.push(x); //cout << x << " "; if (!x) break;
      } //cout << ")\n";
      nw = 0; nx = going_place.front(); remain = fs[nw][nx];
      tasks_ongoing[id] = 0;
    }
    if (remain > 1) {
      //cout << "o";
      cout << nx+1 << endl; remain--; //cout << "^" << going_place.size() << " ";
    }
    else if (remain == 1) {
      //cout << "j";
      cout << nx+1 << endl; remain--;
      if (going_place.size() > 1) {
        nw = nx; going_place.pop(); nx = going_place.front();
        remain = fs[nw][nx]; //cout << nw << " " << nx << endl;
      }
      else if (nx != 0){
        nw = going_place.front(); going_place.pop();
        
        int mn = 1e9, id = 0;
        for(int i=0; i<v; i++) {
          if (tasks_ongoing[i] > 0 && mn > fs[nw][i] / tasks_ongoing[i]) {
            mn = fs[nw][i] / tasks_ongoing[i]; id = i;
          }
        }
        
        for(int x:fs_route[nw][id]) {going_place.push(x); if (!x) break;}
        nx = going_place.front();
        remain = fs[nw][nx];
        tasks_ongoing[id] = 0;
      } else {
        going_place.pop(); nw = 0;
      } 
    }
  }
}

Measured memory_bytes: 61056