#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

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) {
            //vs[0]は1のハズ
            int sz = vs.size();
            if (sz <= 2) return;
            Int best = G.shortest_paths[vs.back()][1].first;
            for (int i = 1; i < vs.size(); ++i) {
                best += G.shortest_paths[vs[i - 1]][vs[i]].first;
            }

            for (int i = 0; i < 3333333; ++i) {
                vector<int> vec(vs.begin(), vs.end());
                int x = rnd() % (sz - 1) + 1;
                int y = rnd() % (sz - 1) + 1;
                while (x == y) {
                    x = rnd() % (sz - 1) + 1;
                    y = rnd() % (sz - 1) + 1;
                }

//                swap(vec[x], vec[y]);
                reverse(vec.begin() + x, vec.begin() + y + 1);
                Int tmp_score = G.shortest_paths[vec.back()][1].first;
                for (int i = 1; i < vec.size(); ++i) {
                    tmp_score += G.shortest_paths[vec[i - 1]][vec[i]].first;
                }

                if (tmp_score < best) {
                    best = tmp_score;
                    vs = vec;
                }

            }

        };

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

        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()) {
//                    sort(all(visit));
//                    visit.erase(unique(visit.begin(), visit.end()), visit.end());
//                    compute_best_path(visit);
//                    moving.add_dests(visit);
//
//                    visit.erase(visit.begin(), visit.end());
//                    visit.push_back(1);
                    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: 6144