#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

const double TL = 27.0;

unsigned int rnd(void) {
    static unsigned int y = 13333;
    y = y ^ (y << 13);
    y = y ^ (y >> 17);
    return y = y ^ (y << 5);
}


//edit
class Graph {
public:
    int V;
    vector<vector<pair<int, int>>> adjacency_list;
    vector<vector<int>> adjacency_matrix;
    vector<vector<pair<int, int>>> shortest_paths;

    Graph(int V) : V(V), adjacency_list(V), adjacency_matrix(V, vector<int>(V, -1)),
                   shortest_paths(V, vector<pair<int, int>>(V, pair<int, int>(INF, -1))) {

        for (int i = 0; i < V; ++i) {
            adjacency_matrix[i][i] = shortest_paths[i][i].first = 0;
        }
    }

    void add_edge(int v1, int v2, int cost) {
        adjacency_list[v1].push_back({v2, cost});
        adjacency_list[v2].push_back({v1, cost});
        adjacency_matrix[v1][v2] = adjacency_matrix[v2][v1] = shortest_paths[v1][v2].first = shortest_paths[v2][v1].first = cost;
        shortest_paths[v1][v2].second = v2;
        shortest_paths[v2][v1].second = v1;
    }

    void compute_shortest_paths() {
        for (int k = 0; k < V; ++k) {
            for (int i = 0; i < V; ++i) {
                for (int j = 0; j < V; ++j) {
//                    shortest_paths[i][j] = min(shortest_paths[i][j], shortest_paths[i][k] + shortest_paths[k][j]);
                    if (shortest_paths[i][k].second != -1 && shortest_paths[k][j].second != -1 &&
                        shortest_paths[i][j].first > shortest_paths[i][k].first + shortest_paths[k][j].first) {
                        shortest_paths[i][j].first = shortest_paths[i][k].first + shortest_paths[k][j].first;
                        shortest_paths[i][j].second = shortest_paths[i][k].second;
                    }
                }
            }
        }
    }

};

class Moving {
public:
    queue<int> dests; //目的地のqueue
    Graph G;
    int from = 1, to = 1;
    int dist = 0; //fromからどれだけ離れているか

    Moving(Graph G) : G(G) {

    }

    void add_dest(int v) {
        dests.push(v);
    }

    void add_dests(vector<int> vs) {
        for (auto e : vs) {
            dests.push(e);
        }
    }

    //目的地に移動しつつ、クエリを出力
    void move_dest() {
        if (from != to) {
            if (dist < G.adjacency_matrix[from][to]) {
                cout << to << endl;
                dist++;
            } else {
                cout << -1 << endl;
            }

            if (dist == G.adjacency_matrix[from][to]) {
                dist = 0;
                from = to;
                while (!dests.empty() && from == dests.front()) {
                    dests.pop();
                }

                if (!dests.empty()) {
                    to = G.shortest_paths[from][dests.front()].second;
                } else {
                    to = from;
                }
            }
        } else {
            while (!dests.empty() && from == dests.front()) {
                dests.pop();
            }

            if (dests.empty()) {
                cout << -1 << endl;
            } else {
                to = G.shortest_paths[from][dests.front()].second;
                move_dest();
            }
        }

    }
};

class Solve {
public:
    int V, E;

    void solve() {
        std::cin >> V >> E;
//        std::vector<std::vector<std::pair<int, int>>> G(V + 1);
        Graph G(V + 1);

        for (int i = 0; i < E; i++) {
            // recieve edges
            int u, v, d;
            std::cin >> u >> v >> d;
            G.add_edge(u, v, d);
        }
        G.compute_shortest_paths();
        Moving moving(G);


        int Tmax;
        std::cin >> Tmax;

        // recieve info
        vector<int> visit;
        visit.push_back(1);
        auto compute_best_path = [&G](vector<int> &vs, double time, double Ts, double Te) {
            // vs.front()とvs.back()を固定して焼きなましを行う
            if (vs.size() <= 3) return;
            Int best_score = 0;
            vector<int> best_state = vs;
            for (int i = 1; i < vs.size(); ++i) {
                best_score += G.shortest_paths[vs[i - 1]][vs[i]].first;
            }
            Int cur_score = best_score;
            vector<int> cur_state = vs;

            clock_t begin_time = clock();
            while (true) {
                clock_t current_time = clock();
                double elapsed_time = (current_time - begin_time) / CLOCKS_PER_SEC;
                if (elapsed_time > time) break;

                int x = rnd() % (vs.size() - 2) + 1;
                int y = rnd() % (vs.size() - 2) + 1;
                if (x == y) {
                    x = rnd() % (vs.size() - 2) + 1;
                    y = rnd() % (vs.size() - 2) + 1;
                }
                if (x > y) swap(x, y);

                reverse(cur_state.begin() + x, cur_state.begin() + y + 1);
                Int new_score = 0;
                for (int i = 1; i < cur_state.size(); ++i) {
                    new_score += G.shortest_paths[cur_state[i - 1]][cur_state[i]].first;
                }

                Int diff_score = new_score - cur_score;
                if (diff_score < 0) {
                    cur_score = new_score;
                } else {
                    double Tc = (Te - Ts) * (elapsed_time / time) + Ts;
                    double P = exp(-diff_score / Tc);
                    Int R = 100000000;
                    if (rnd() % R < P * R) {
                        cur_score = new_score;
                    } else {
                        reverse(cur_state.begin() + x, cur_state.begin() + y + 1);
                    }
                }

                if (cur_score < best_score) {
                    best_score = cur_score;
                    best_state = cur_state;
                }
            }

            vs = best_state;
        };

        vector<int> visit2;
        for (int idx = 1; idx <= V; ++idx) {
            visit2.push_back(idx);
        }
        visit2.push_back(1);

//        compute_best_path(visit2, TL, 2e3, 1e-10);
        compute_best_path(visit2, TL, 2e1, 1e-10);

        for (int i = 0; i < Tmax; i++) {
            int Nnew;
            std::cin >> Nnew;
            for (int j = 0; j < Nnew; j++) {
                int new_id, dst;
                std::cin >> new_id >> dst;
                visit.push_back(dst);
                if (moving.dests.empty()) {
                    moving.add_dests(visit2);
                }
            }
            if (moving.dests.empty()) {
                moving.add_dests(visit2);
            }
            moving.move_dest();
            if (moving.dist == 0 && moving.from == 1) {
                cerr << i << endl;
            }
        }
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 8064