#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> Path;

const int INF = (1<<28);

ll SCORE = 0;
clock_t START, END;

class Edge{
public:
  int from, to, cost;

  Edge() : cost(INF) {}
  Edge(int s, int t, int d) : from(s), to(t), cost(d) {}
};

class Graph {
public:
  int N, M;
  vector<vector<Edge>> edges;
  vector<vector<int>> dists;
  vector<vector<Path>> paths;

  Graph() {}
  Graph(int _N, int _M) : N(_N), M(_M),
                          edges(N, vector<Edge>(N, Edge())),
                          dists(N, vector<int>(N, INF)),
                          paths(N, vector<vector<int>>(N)) {}

  void input() {
    for (int i = 0; i < M; i++) {
      int s, t, d;
      scanf("%d %d %d", &s, &t, &d);
      s--; t--;
      edges[s][t] = Edge(s, t, d);
      edges[t][s] = Edge(t, s, d);
    }
  }

  void init() {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (edges[i][j].cost == INF) continue;
        dists[i][j] = dists[j][i] = edges[i][j].cost;

        Path p1, p2;
        p1.push_back(i); p1.push_back(j);
        p2.push_back(j); p2.push_back(i);
        paths[i][j] = p1;
        paths[j][i] = p2;
      }
      dists[i][i] = 0;
      paths[i][i] = Path(1, i);
    }
    for (int k = 0; k < N; k++) {
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
          int tmp = dists[i][k] + dists[k][j];
          if (tmp < dists[i][j]) {
            dists[i][j] = tmp;

            Path path = paths[i][k];
            path.insert(path.end(), paths[k][j].begin()+1, paths[k][j].end());
            paths[i][j] = path;
          }
        }
      }
    }
  }
};


class Order {
public:
  int ID, DST;
  int t;

  Order() {}
  Order(int _ID, int _DST, int _t) : ID(_ID), DST(_DST), t(_t) {}
};

class OrderList {
public:
  int T;
  vector<Order> list;

  OrderList() {}
  OrderList(int _T) : T(_T), list(T) {}
  void input() {
    for (int t = 0; t < T; t++) {
      int n; scanf("%d", &n);
      int id, dst;
      if (n == 0) {
        id = dst = INF;
      } else {
        scanf("%d %d", &id, &dst);
        dst--;
      }
      list[t] = Order(id, dst, t);
    }
  }
  void init() {}
};


class Solver {
public:
  const int SKIP_NUM = 3;
  const int MAX_Iter = 1;   // 温度変更回数
  double INI_TEMP = 100;
  int time;
  Graph G;
  OrderList ol;
  Path ans;

  Solver(Graph _G, OrderList _ol) : time(0), G(_G), ol(_ol) {}


  // TODO : 高速化
  ll evaluate_path(Path path, vector<vector<Order>> orders) {
    ll score = 0;
    int len = path.size(), t = time;
    // uso
    for (int i = 1; i < len; i++) {
      int from = path[i-1], to = path[i];
      if (to == 0) break;
      t += G.dists[from][to];
      if (t >= ol.T) break;
      for (int j = 0; j < orders[to].size(); j++) {
        score += (pow(ol.T,2) - pow(t - orders[to][j].t, 2));
      }
      orders[to].clear();
    }
    return score;
  }

  // TODO : 高速化
  Path make_path(int s, vector<int> dest_order, int t) {
    int now = s, next = dest_order[0];
    Path path(1, now);
    dest_order.push_back(t);

    vector<bool> visited(G.N, false);
    for (int i = 0; i < dest_order.size(); i++) {
      next = dest_order[i];
      if (visited[next]) continue;
      visited[next] = true;
      Path now_to_next = G.paths[now][next];
      for (int j = 1; j < now_to_next.size(); j++) {
        next = now_to_next[j];
        path.push_back(next);
        visited[next] = true;
      }
      now = next;
    }
    return path;
  }

  double exchange_probability(double diff, double temp){
    return exp(-diff / temp);
  }

  double calc_temperature(int iteration){
    return (double)INI_TEMP - pow(INI_TEMP, double(iteration)/MAX_Iter);
  }

  // TODO : 最適化
  vector<int> init_order(vector<vector<Order>> orders) {
    int now = 0;
    vector<int> dest_order;
    vector<bool> go(G.N, false);
    for (int i = 0; i < G.N; i++) {
      go[i] = !orders[i].empty();
    }
    for (int i = 0; i < G.N; i++) {
      int mn = INF, next = -1;
      for (int j = 0; j < G.N; j++) {
        if (go[j] && G.dists[now][j] < mn) {
          mn = G.dists[now][j];
          next = j;
        }
      }
      if (next == -1) break;
      go[next] = false;
      dest_order.push_back(next);
      now = next;
    }
    return dest_order;
  }

  // TODO : 高速化、温度による許容の部分
  Path search_path(vector<Order> ordlist) {
    vector<vector<Order>> orders(G.N);
    for (int i = 0; i < ordlist.size(); i++) {
      Order ord = ordlist[i];
      orders[ord.DST].push_back(ord);
    }

    // 初期値の決定
    vector<int> dest_order = init_order(orders);

    // simulated annealing ???
    Path res_path = make_path(0, dest_order, 0);
// return res_path;
    ll pre_score = evaluate_path(res_path, orders);
    ll max_score = pre_score;
cerr << "parcel num : " << ordlist.size() << endl;
cerr << "first score: " << pre_score << endl;

    random_device seed;
    mt19937 mt(seed());
    uniform_real_distribution<> rand01(0.0, 1.0);

    int N = dest_order.size();
// cerr << "dest_order: ";
// for (int i = 0; i < N; i++) {
//   cerr << dest_order[i] << " \n"[i==N-1];
// }
    map<vector<int>, pair<Path, ll>> checked;
    checked[dest_order] = make_pair(res_path, pre_score);
    for (int iter = 0; iter < MAX_Iter; iter++) {
      double temp = calc_temperature(iter+1);
// cerr << iter << ", tmep: " << temp << endl;

      for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
// cerr << "(i, j) = (" << i << ", " << j << ")\n";
          vector<int> new_order = dest_order;
          if (rand01(mt) <= 0.5) {
            swap(new_order[i], new_order[j]);
          } else {
            reverse(new_order.begin()+i, new_order.begin()+j+1);
          }

          Path new_path;
          ll new_score;
          if (1 || checked.find(new_order) == checked.end()) {
            new_path  = make_path(0, new_order, 0);
            new_score = evaluate_path(new_path, orders);
            // checked[new_order] = make_pair(new_path, new_score);
          } else {
            new_path  = checked[new_order].first;
            new_score = checked[new_order].second;
          }

          ll diff = new_score - pre_score;
          if (diff > 0) {
// cerr << "pre_score: " << pre_score << ", new_score: " << new_score << endl;
            dest_order = new_order;
            pre_score = new_score;
            if (new_score > max_score) {
              max_score = new_score;
              res_path = new_path;
// cerr << "max_score: " << max_score << endl;
            }
          } else if (diff < 0) {
            double prob = exchange_probability(-diff, temp*ol.T*ol.T);
// cerr << "temp: " << temp << ", prob: " << prob << endl;
            if (prob >= rand01(mt)) {
              dest_order = new_order;
              pre_score = new_score;
            }
          }
        }
      }
    }
cerr << "last score : " << max_score << endl;
cerr << "max score  : " << (ll)ordlist.size() * ol.T * ol.T << endl;
cerr << "diff score : " << -((ll)ordlist.size() * ol.T * ol.T - max_score) << endl;
SCORE += max_score;
    return res_path;
  }

  vector<Order> execute(Path path, vector<Order> ordlist) {
    vector<bool> visited(G.N, false);
    vector<Order> new_ordlist;
    int len = path.size();
    int now_node = path[0];
    for (int i = 1; i < len; i++) {
      int next_node = path[i];
      int dt = G.edges[now_node][next_node].cost;
      for (int t = time; t < min(time+dt, ol.T); t++) {
        ans.push_back(next_node+1);
        Order ord = ol.list[t+1];
        if (ord.ID != INF) new_ordlist.push_back(ord);
      }
      time += dt;

      visited[next_node] = true;
      now_node = next_node;

      // 途中で店舗に戻った場合
      if (now_node == 0) break;
    }

    // old_orderlistのチェック
    for (int i = 0; i < ordlist.size(); i++) {
      if (!visited[ordlist[i].DST]) {
        new_ordlist.push_back(ordlist[i]);
      }
    }
    return new_ordlist;
  }

  void solve() {
    vector<Order> ordlist;
    while (time < ol.T) {
      while (ordlist.size() < SKIP_NUM && time < ol.T) {
        Order ord = ol.list[time];
        if (ord.ID != INF) ordlist.push_back(ord);
        ans.push_back(-1);
        time++;
      }
      if (ordlist.empty()) break;
      Path path = search_path(ordlist);
      cerr << endl;
      ordlist = execute(path, ordlist);
    }
    cerr << "    score = " << SCORE << endl;
    cerr << "est_score = " << 30*SCORE << endl;
  }

  void output() {
    int sz = ans.size();
    if (sz < ol.T) {
      for (int i = 0; i < sz; i++) cout << ans[i] << endl;
      for (int i = 0; i < ol.T-sz; i++) cout << -1 << endl;
    } else {
      for (int i = 0; i < ol.T; i++) cout << ans[i] << endl;
    }
  }
};


/* ==================== main ==================== */
int main() {
  START = clock();

  int N, M; scanf("%d %d", &N, &M);
  Graph G(N, M);
  G.input();
  G.init();

  int T; scanf("%d", &T);
  OrderList ol(T);
  ol.input();
  ol.init();

  Solver sl(G, ol);
  sl.solve();
  sl.output();

  END = clock();
  cerr << "time: " << (double)(END - START)/CLOCKS_PER_SEC << endl;
  return 0;
}


Measured memory_bytes: 64640