#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#define inf 100000000
using namespace std;
typedef long long int ll;

int V, E;
vector<pair<int,int>> EDGE[400];
int DIST[400][400];
const int Tmax = 10000;
int ORDER[Tmax];

struct TRIP {
    int st, en; // start
    vector<int> p; // points, to 0
};

struct HISTORY {
    vector<TRIP> trips;

    void output() {
        int now = 0;
        for (TRIP& trip: trips) {
            while (now < trip.st) {
                cout << -1 << endl;
                now++;
            }
            int pos = 0;
            for (int p : trip.p) {
                while (pos != p) {
                    for (pair<int,int>& e: EDGE[pos]) {
                        if (DIST[pos][p] != DIST[e.first][p]+e.second) continue;
                        for (int _ = 0; _ < e.second; _++) {
                            cout << e.first+1 << endl;
                            now++;
                            if (now >= Tmax) break;
                        }
                        pos = e.first;
                        break;
                    }
                    if (now >= Tmax) break;
                }
                if (now >= Tmax) break;
            }
            if (now >= Tmax) break;
        }
        while (now < Tmax) {
            cout << -1 << endl;
            now++;
        }
    }
};

struct STATE {
    ll score;
    ll t;
    HISTORY history;
    vector<pair<int, int>> orders;

    STATE() {
        score = 0;
    }
};

void init() {
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            DIST[i][j] = inf;
        }
        DIST[i][i] = 0;
    }
    for (int i = 0; i < V; i++) {
        for (pair<int, int>& e: EDGE[i]) {
            DIST[i][e.first] = min(DIST[i][e.first], e.second);
        }
    }
    for (int u = 0; u < V; u++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                DIST[i][j] = min(DIST[i][j], DIST[i][u] + DIST[u][j]);
            }
        }
    }
}

void input() {
    cin >> V >> E;
    for(int i = 0; i < E; i++) {
        // recieve edges
        int u, v, d; std::cin >> u >> v >> d;
        u--; v--;
        EDGE[u].push_back({v, d});
        EDGE[v].push_back({u, d});
    }
    int _;
    cin >> _;
    // recieve info
    for(int i = 0; i < Tmax; i++) {
        int Nnew; cin >> Nnew;
        if (Nnew == 0) ORDER[i] = -1;
        else {
            int new_id, dst; cin >> new_id >> dst;
            ORDER[i] = dst-1;
        }
    }
}

void optimize_path(vector<int>& path) {
    int n = path.size();
    while (true) {
        bool end = true;
        for (int i = 0; i < n; i++) {
            for (int j = i+2; j < n-1; j++) {
                int ori_dist = DIST[path[i]][path[i+1]] + DIST[path[j]][path[j+1]];
                int new_dist = DIST[path[i]][path[j]] + DIST[path[i+1]][path[j+1]];
                if (ori_dist > new_dist) {
                    end = false;
                    int swap_st = i+1, swap_en = j;
                    while (swap_st < swap_en) {
                        swap(path[swap_st], path[swap_en]);
                        swap_st++;
                        swap_en--;
                    }
                }
            }
        }
        if (end) break;
    }
}

int tsp(STATE& state, int st_time) {
    vector<int> points;
    for (pair<int,int>& o : state.orders) {
        points.push_back(o.first);
    }
    points.push_back(0);
    sort(points.begin(), points.end());
    points.erase(unique(points.begin(), points.end()), points.end());

    vector<bool> saw((int)points.size(), false);
    vector<int> path((int)points.size());
    int pre = 0;
    saw[pre] = true;
    for (int i = 0; i < (int)points.size()-1; i++) {
        int dis = inf;
        int to = -1;
        for (int j = 0; j < (int)points.size(); j++) {
            if (saw[j]) continue;
            if (dis > DIST[points[pre]][points[j]]) {
                dis = DIST[points[pre]][points[j]];
                to = j;
            }
        }
        pre = to;
        saw[to] = true;
        path[i] = points[to];
    }
    path[(int)points.size()-1] = points[0];
    optimize_path(path);
    int total_time = 0;
    for (int i = 0; i < (int)path.size(); i++) {
        if (i == 0) total_time += DIST[0][path[i]];
        else total_time += DIST[path[i-1]][path[i]];
    }
    TRIP trip;
    trip.st = st_time;
    trip.en = trip.st+total_time;
    trip.p = path;
    state.history.trips.push_back(trip);
    return total_time;
}

void solve() {
    STATE state;
    int t = 0;
    while (true) {
        if (t >= Tmax) break;
        if (ORDER[t] != -1) {
            state.orders.push_back(pair<int,int>(ORDER[t], t));
        }
        if (state.orders.size() == 0) {
            t++;
            continue;
        }
        int trip_time = tsp(state, t);
        state.orders.clear();
        for (int _ = 0; _ < trip_time; _++) {
            t++;
            if (ORDER[t] != -1) {
                state.orders.push_back(pair<int,int>(ORDER[t], t));
            }
        }
        t++;
    }
    state.history.output();
}

int main() {
    input();

    init();

    solve();

    return 0;
}


Measured memory_bytes: 1024