//#2-opt, SA

#include <iostream>
#include <algorithm>

#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>

#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>

#include<memory>


using namespace std;
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double,int> pdi;
typedef pair<long double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<29;
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;
const ll mod = 1000000000 + 7;
//const ll mod = 998244353;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const long double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

//debug
#define DEBUG

#define DUMPOUT cerr

#ifdef DEBUG
#define dump(...) DUMPOUT<<#__VA_ARGS__<<" :["<<__FUNCTION__<<":"<<__LINE__<<"]"<<endl; DUMPOUT<<"    "; dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif

void dump_func() {DUMPOUT << endl;};

template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) DUMPOUT << " ";
    else DUMPOUT << ", ";
    dump_func(std::move(tail)...);
}

//ostream
template<typename T> ostream& operator << (ostream& os, vector<T>& vec) {
    os << "["; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "]";
    return os;
}

template<typename T, typename U> ostream& operator << (ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}

template<typename T, typename U> ostream& operator << (ostream& os, map<T, U>& map_var) {
    os << "[";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")"; itr++;  if(itr != map_var.end()) os << ", "; itr--;
    }
    os << "]";
    return os;
}

template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {
    os << "[";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr; ++itr; if(itr != set_var.end()) os << ", "; itr--;
    }
    os << "]";
    return os;
}

auto start = chrono::system_clock::now();

inline bool check_time(double Limit_time) {
    auto end = chrono::system_clock::now();
    auto dur = end - start;
    auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
    if (msec >= Limit_time) return false;
    return true;
}

inline double get_time() {
  auto end = chrono::system_clock::now();
  auto dur = end - start;
  auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  return msec;
}

inline void now_time() {
  auto end = chrono::system_clock::now();
  auto dur = end - start;
  auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  cout << "time : " << msec << " msec"<< endl;
}

unsigned long long seed128[4]; //x,y,z,wとして利用
inline void seed(unsigned long long s){
    for(int i=1; i<=4; i++){
        seed128[i-1] = s = 1812433253U * (s^(s>>30)) + i;
    }
}

inline unsigned long long Xor128(){
  unsigned long long t;
  t=(seed128[0]^(seed128[0]<<11));
  seed128[0]=seed128[1];
  seed128[1]=seed128[2];
  seed128[2]=seed128[3];
  seed128[3]=(seed128[3]^(seed128[3]>>19))^(t^(t>>8));
  return seed128[3];
}

int n, m; //頂点数, 辺数
vector<vector<pair<int, int>>> g;
const int T = 10000;
vector<pii> order; //(id, v) ただし(-1, -1)は注文がないことを表す
int order_cnt = 0; //注文数
vector<int> start_o; //start_o[id]:= 注文idを開始した時刻
vector<vector<int>> order_info; //order_info[v]:= 頂点vの注文リスト
vector<bool> finished_order; //注文を聞いたかどうか

vector<vector<int>> d; //d[i][j]:= iからjへの最短経路距離
vector<vector<vector<int>>> path; //d[i][j]:= iからjへの最短経路path
int delivery_cnt = 0; //達成した注文数


void read() {
  //input graph
  cin >> n >> m;
  g.resize(n);
  rep(i, m) {
    int u, v, c;
    cin >> u >> v >> c;
    u--; v--;
    g[u].emplace_back(v, c);
    g[v].emplace_back(u, c);
  }
  /*
  rep(i, (int)g[0].size()) {
    cerr << g[0][i] << " ";
  }
  cerr << endl;
  exit(0);
  */
  //input order
  order_info.resize(n);
  int tmp_T;
  cin >> tmp_T;
  assert(tmp_T == T);
  rep(i, T) {
    int info;
    cin >> info;
    if (info == 0) {
      order.emplace_back(-1, -1);
      continue;
    }
    assert(info == 1);
    order_cnt++;
    int id, v;
    cin >> id >> v;
    id--; v--;
    order.emplace_back(id, v);
    start_o.push_back(i);
  }
  finished_order.resize(order_cnt);
  rep(i, order_cnt) finished_order[i] = false;
  assert((int)start_o.size() == order_cnt);
}

void analysis() {
    //cerr << order_cnt << endl;
    //各頂点の注文数
    int region[n] = {};
    rep(i, T) {
      if (order[i].fi == -1) continue;
      region[order[i].se]++;
    }
    vector<pii> freq;
    rep(i, n) freq.emplace_back(region[i], i);
    sort(rall(freq));
    rep(i, n) {
      cerr << freq[i].se+1 << " " << freq[i].fi << endl;
    }


    //注文率([-range/2, range/2]の平均)
    int range = 1000;
    vector<double> rates;
    rep2(i, range/2, T-range/2) {
      double rate = 0;
      rep2(j, i-range/2, i+range/2+1) {
        if (order[j].fi == -1) continue;
        rate++;
      }
      rate /= (double)range;
      cout << i << " " << rate << endl;
      rates.push_back(rate);
    }
  }

vector<int> dijkstra(const int s, const int n, vector<int>& pv, const vector<vector<pii>>& g) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  vector<int> d(n, INF); d[s] = 0;
  que.emplace(0, s);
  while (!que.empty()) {
    pii p = que.top();que.pop();
    int fr = p.second;
    if (d[fr] < p.first) continue;
    for (pair<int, int> e: g[fr]) {
      int to = e.fi;
      int cost = e.se;
      if (d[to] > d[fr] + cost) {
        d[to] = d[fr] + cost;
        pv[to] = fr;
        que.emplace(d[to], to);
      }
    }
  }
  return d;

}

vector<int> get_path(int t, const vector<int>& pv) {
    vector<int> path;
    while (t != -1) {
      path.push_back(t);
      t = pv[t];
    }
    reverse(path.begin(),path.end());
    return path;
}

void calc_graph() {
  d.resize(n);
  path.resize(n);
  rep(i, n) path[i].resize(n);

  rep(i, n) {
    vector<int> pv(n, -1);
    d[i] = dijkstra(i, n, pv, g);
    rep(j, n) {
      if (i == j) continue;
      path[i][j] = get_path(j, pv);
    }
  }
}

//nowtでidの注文を完了した時に、それによって得られるスコア
double calc_value(const int nowt, const int id) {
  double wait = (nowt - start_o[id]);
  return max(0.0, (double)T*T - wait*wait);
}


void output(const vector<int>& ans) {
  rep(i, T) {
    if (ans[i] == -1) cout << ans[i] << endl;
    else cout << ans[i]+1 << endl;
  }
}

void update_ans(double& score, int& pret, int& nowt, const vector<int>& TSP_path, set<pii>& can_delivery, vector<int>& ans) {
  assert(TSP_path[0] == 0);
  assert(TSP_path[(int)TSP_path.size()-1] == 0);
  //rep2(i, 1, (int)TSP_path.size()-1) assert(TSP_path[i] != 0);

  rep(i, (int)TSP_path.size()-1) {
    int now = TSP_path[i];
    int nx = TSP_path[i+1];
    if (nowt + d[now][nx] > T) {
      cerr << "score : " << (ll)score << " order_cnt : " << order_cnt << " delivery_cnt : " << delivery_cnt << " delivery_rate : " << (double)delivery_cnt / order_cnt << endl;
      output(ans);
      exit(0);
    }
    rep(j, d[now][nx]) {
      ans[nowt++] = nx;
    }
    if ((int)order_info[nx].size() != 0) {
      for (int id : order_info[nx]) {
        delivery_cnt++;
        score += calc_value(nowt, id);
        can_delivery.erase({id, nx});
      }
      order_info[nx].clear();
    }
    if (nx == 0) {
      while (pret <= nowt) {
        int id = order[pret].fi;
        int v = order[pret].se;
        if (id != -1 && !finished_order[id]) {
          finished_order[id] = true;
          can_delivery.insert(order[pret]);
          order_info[v].push_back(id);
        }
        pret++;
      }
    }
  }
  return;
}

const int TSP_size_limit = 0;
int dp[(1LL<<TSP_size_limit)][TSP_size_limit];

vector<pii> exact_TSP(const vector<pii>& DS) {
  //時間最小だが、評価値最小にすべき？
  vector<pii> TSP_ans;
  vector<pii> tmpDS;
  tmpDS.emplace_back(-1, 0);
  for (auto p : DS) tmpDS.push_back(p);

  int sz = (int)tmpDS.size();
  cerr << sz << endl;
  rep(i, (1LL<<TSP_size_limit))rep(j, TSP_size_limit) dp[i][j] = INF;
  dp[1][0] = 0;
  rep2(i, 1, (1LL<<sz)) {
    rep2(j, 1, sz) {
      if (i>>j&1) continue;
      rep(k, sz) {
        if (i>>k&1) {
          int fr = tmpDS[k].se;
          int to = tmpDS[j].se;
          dp[i^(1LL<<j)][j] = min(dp[i^(1LL<<j)][j], dp[i][k] + d[fr][to]);
        }
      }
    }
  }
  int mn = INF;
  int t = -1;
  rep2(j, 1, sz) {
    int fr = tmpDS[j].se;
    int to = 0;
    cerr << "cost : " << dp[(1LL<<sz)-1][j] << " j : " << tmpDS[j].se << endl;
    if (dp[(1LL<<sz)-1][j] + d[fr][to] < mn) {
      t = j;
      mn = dp[(1LL<<sz)-1][j] + d[fr][to];
    }
  }
  assert(t != -1);
  bool visited[sz] = {};
  int nowS = (1LL<<sz)-1;
  TSP_ans.emplace_back(tmpDS[0]);
  while (true) {
    TSP_ans.emplace_back(tmpDS[t]);
    int nxtS = nowS;
    nowS ^= (1LL<<t);
    bool update = false;
    rep(j, sz) {
      if (visited[j]) continue;
      int fr = tmpDS[j].se;
      int to = tmpDS[t].se;
      if (dp[nxtS][t] == dp[nowS][j] + d[fr][to]) {
        visited[j] = true;
        t = j;
        update = true;
        break;
      }
    }
    if (!update) break;
  }
  //TSP_ans.emplace_back(-1, 0);
  return TSP_ans;
}

vector<pii> heulistic_TSP(const int nowt, const vector<pii>& DS) {
  vector<vector<int>> VS;
  map<int, int> mp, v_idx;
  int cnt_v = 0;
  for (auto p : DS) {
    if (mp.find(p.se) == mp.end()) {
      v_idx[cnt_v] = p.se;
      mp[p.se] = cnt_v++;
    }
  }
  VS.resize((int)mp.size());
  for (auto p : DS) {
    int id = p.fi;
    int v = p.se;
    VS[mp[v]].push_back(id);
  }
  vector<pii> TSP_ans;
  int cnt = VS.size();
  int now = 0;
  int tmp_nowt = nowt;
  TSP_ans.emplace_back(-1, 0);
  bool visited[cnt] = {};
  while (cnt > 0) {
    double mn_score = T+1;
    int nx = -1;
    rep(i, (int)VS.size()) {
      int v = v_idx[i];
      if (visited[i]) continue;
      int tmpt = tmp_nowt + d[now][v];
      double tmp_score = tmpt;
      if (tmp_score < mn_score) {
        mn_score = tmp_score;
        nx = i;
      }
    }
    if (nx == -1) break; //TSP完了
    cnt--;
    visited[nx] = true;
    int nx_v = v_idx[nx];
    bool via_store = false;
    rep2(i, 1, (int)path[now][nx_v].size()) {
      if (path[now][nx_v][i] == 0) {
        via_store = true;
        break;
      }
    }
    if (via_store) {
      TSP_ans.emplace_back(-1, 0);
      return TSP_ans;
    }
    for (auto nx_id : VS[nx]) {
      TSP_ans.emplace_back(nx_id, nx_v);
    }
    tmp_nowt += d[now][nx_v];
    now = nx_v;
  }
  TSP_ans.emplace_back(-1, 0);
  return TSP_ans;

}

pair<int, int> opt2_SA(double& Score, vector<int>& TSP_path) {
  int u = -1;
  int v = -1;
  int sz = TSP_path.size();
  int s = 0;
  int t = sz-1;
  int loop = 0;
  int limit_loop = 1000;
  while (loop < limit_loop && (u == v || u == s || v == t)) {
    loop++;
    u = Xor128() % sz;
    v = Xor128() % sz;
    if (u > v) swap(u, v);
  }
  if (loop == limit_loop) return {-1, -1};
  double diff_score = d[TSP_path[u-1]][TSP_path[u]] + d[TSP_path[v]][TSP_path[v+1]];
  Score -= diff_score;
  diff_score = d[TSP_path[u-1]][TSP_path[v]] + d[TSP_path[u]][TSP_path[v+1]];
  Score += diff_score;
  return {u, v};
}

void NeighborSearch(double& Score, vector<int>& TSP_path) {
  int id = Xor128() % 1;
  if (id == 0) opt2_SA(Score, TSP_path);
}

vector<int> SA(const int nowt, const vector<pii>& DS, const vector<pii>& TSP_ans) {
  //construct TSP_path
  assert(TSP_ans[0].se == 0);
  assert(TSP_ans[(int)TSP_ans.size()-1].se == 0);
  vector<int> TSP_path;
  double tmp_nowt = 0;
  rep(i, (int)TSP_ans.size()) {
    TSP_path.push_back(TSP_ans[i].se);
    if (i != (int)TSP_ans.size()-1) {
      int now = TSP_ans[i].se;
      int nx = TSP_ans[i+1].se;
      tmp_nowt += d[now][nx];
    }
  }
  /*
  rep(i, (int)TSP_ans.size()-1) {
    int now = TSP_ans[i].se;
    int nx = TSP_ans[i+1].se;
    rep(j, (int)path[now][nx].size()-1) {
      int pnow = path[now][nx][j];
      TSP_path.push_back(pnow);
    }
    tmp_nowt += d[now][nx];
    if (i+1 == (int)TSP_ans.size()-1) {
      assert(TSP_ans[i+1].se == 0);
      TSP_path.push_back(0);
    }
  }
  */
  if (TSP_ans.size() <= 3) return TSP_path;
  rep2(i, 1, (int)TSP_path.size()-1) {
    assert(TSP_path[i] != 0);
  }
  assert(TSP_path[0] == 0);
  assert(TSP_path[(int)TSP_path.size()-1] == 0);

  //start SA;
  double limit_time = 200;

  double bestScore = tmp_nowt;
  vector<int> bestPath = TSP_path;

  double curScore = tmp_nowt;
  vector<int> curPath = TSP_path;

  double startTemp = 1.0;
  double endTemp = 0;
  double st_time = get_time();

  int R = INF;
  int loop = 0;
  //cerr << "before time : " << tmp_nowt << endl;
  while (true) {
    loop++;
    double t = get_time() - st_time;
    double temp = startTemp + (endTemp - startTemp) * t / limit_time;
    if (temp <= 0) break;
    double nextScore = curScore;
    pair<int, int> p = opt2_SA(nextScore, curPath);
    if (p.fi == -1 && p.se == -1) break;
    //NeighborSearch(nextTime, nextPath);
    double prob = exp((curScore - nextScore) / temp);
    bool FORCE = prob > (double)(Xor128() % R) / R;
    if (FORCE) {
      curScore = nextScore;
      int u = p.fi;
      int v = p.se;
      reverse(curPath.begin()+u, curPath.begin()+v+1);
      if (curScore < bestScore) {
        bestScore = curScore;
        bestPath = curPath;
      }
    }
    if (loop % 100 == 0) {
      //cerr << "loop : " << loop << " curScore : " << curScore << " bestScore : " <<  bestScore << " temp :"<< temp << endl;
    }
  }
  //cerr << "after time : " << bestScore << endl;
  //cerr << "-----------" << endl;
  return bestPath;
}

//最小単位で表現 (u->vをu->w->v)
vector<int> trans_minimum(vector<int> TSP) {
  vector<int> ret;
  rep(i, (int)TSP.size()-1) {
    int now = TSP[i];
    int nx = TSP[i+1];
    rep(j, (int)path[now][nx].size()-1) {
      ret.push_back(path[now][nx][j]);
    }
    if (i == (int)TSP.size() - 2) {
      assert(nx == 0);
      ret.push_back(0);
    }
  }
  return ret;
}


bool delivery(double& score, int& pret, int& nowt, set<pii>& can_delivery, vector<int>& ans) {
  vector<pii> DS; //DS:Sの部分集合, Sのうち今から配達する頂点集合(すべて配達するのが高スコアの必要条件そう)
  for (auto p : can_delivery) {
    DS.emplace_back(p);
  }
  vector<pii> TSP_ans;
  vector<int> TSP_path;
  if (DS.size() < TSP_size_limit) {
    //cerr << "exact_TSP" << endl;
    TSP_ans = exact_TSP(DS);
    if ((int)TSP_ans.size() == 2) return false;
  }
  else {
    //cerr << "heulistic_TSP" << endl;
    TSP_ans = heulistic_TSP(nowt, DS);
    if ((int)TSP_ans.size() == 2) return false;
    TSP_path = SA(nowt, DS, TSP_ans);
    TSP_path = trans_minimum(TSP_path);
  }
  update_ans(score, pret, nowt, TSP_path, can_delivery, ans);
  return true;
}


vector<int> solve() {
  double score = 0;
  int nowt = 0;
  vector<int> ans(T, -1);
  set<pii> can_delivery;
  while (nowt < T) {
    while (nowt < T && (int)can_delivery.size() == 0) {
      int id = order[nowt].fi;
      int v = order[nowt].se;
      if (id != -1 && !finished_order[id]) {
        finished_order[id] = true;
        can_delivery.insert(order[nowt]);
        order_info[v].push_back(id);
        break;
      }
      nowt++;
    }
    if (nowt == T) break;
    //cerr << "will deliver " << nowt << endl;
    int pret = nowt+1;
    bool update = delivery(score, pret, nowt, can_delivery, ans);
    //cerr << pret << " " << nowt << " " << can_delivery.size() << endl;
    if (!update) {
      while (pret < T) {
        int id = order[pret].fi;
        int v = order[pret].se;
        if (id != -1 && !finished_order[id]) {
          finished_order[id] = true;
          can_delivery.insert(order[pret]);
          order_info[v].push_back(id);
          break;
        }
        pret++;
      }
      nowt = pret;
    }
  }
  cerr << "score : " << (ll)score << " order_cnt : " << order_cnt << " delivery_cnt : " << delivery_cnt << " delivery_rate : " << (double)delivery_cnt / order_cnt << endl;
  return ans;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  seed(37);
  read();
  //cerr << "read passed" << endl;
  calc_graph();
  //cerr << "calc_graph passed" << endl;
  //analysis();
  vector<int> ans = solve();
  //cerr << "solve passed" << endl;
  output(ans);
}


Measured memory_bytes: 21760