#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> P;

const int INF = 100000000;

int n;

int dis[500][500];
int pre[500][500];  //iからjへ行く最短ルートでjの1個前に通るところ
int der[500];

int go(int k, int l){  //kからl
    int res = 0;
    int now = k;
    while(pre[l][now] != -1){
        res += dis[now][pre[l][now]];
        for(int i = 0; i < dis[now][pre[l][now]]; i++) cout << pre[l][now] + 1 << endl;
        now = pre[l][now];
    }
    return res;
}

int roop(int restt){
    vector<int> r;
    r.push_back(0);
    r.push_back(0);
    for(int i = 1; i < n; i++){
        if(der[i] > 0){
            int ins = -1;
            int les = 100000000;
            for(int j = 0; j < (int)r.size() - 1; j++){
                if(dis[r[j]][i] + dis[i][r[j + 1]] < les){
                    ins = j + 1;
                    les = dis[r[j]][i] + dis[i][r[j + 1]];
                }
            }
            r.insert(r.begin() + ins, i);
        }
    }
    for(int c = 0; c < 5; c++){
        for(int i = 0; i < (int)r.size() - 1; i++){
            for(int j = 0; j < (int)r.size() - 1; j++){
                if(dis[r[i]][r[i + 1]] + dis[r[j]][r[j + 1]] > dis[r[i]][r[j]] + dis[r[i + 1]][r[j + 1]]){
                    for(int k = i + 1; k < (i + 2 + j) / 2; k++) swap(r[k], r[i + 1 + j - k]);
                }
            }
        }
    }
    for(int c = 0; c < 10; c++){
        for(int i = 0; i < (int)r.size() - 1; i++){
            for(int j = i + 2; j < (int)r.size() - 1; j++){
                for(int k = j + 2; k < (int)r.size() - 1; k++){
                    if(dis[r[i]][r[i + 1]] + dis[r[j]][r[j + 1]] + dis[r[k]][r[k + 1]] >
                       dis[r[i]][r[j + 1]] + dis[r[j]][r[k + 1]] + dis[r[k]][r[i + 1]]){
                        vector<int> x(j - i), y(k - j);
                        for(int l = 0; l < j - i; l++){
                            x[l] = r[l + i + 1];
                        }
                        for(int l = 0; l < k - j; l++){
                            y[l] = r[l + j + 1];
                        }
                        for(int l = 0; l < k - j; l++){
                            r[l + i + 1] = y[l];
                        }
                        for(int l = 0; l < j - i; l++){
                            r[l + i + k - j + 1] = x[l];
                        }
                    }
                    if(dis[r[i]][r[i + 1]] + dis[r[j]][r[j + 1]] + dis[r[k]][r[k + 1]] >
                       dis[r[i]][r[k]] + dis[r[j]][r[k + 1]] + dis[r[j + 1]][r[i + 1]]){
                        vector<int> x(j - i), y(k - j);
                        for(int l = 0; l < j - i; l++){
                            x[l] = r[l + i + 1];
                        }
                        for(int l = 0; l < k - j; l++){
                            y[l] = r[l + j + 1];
                        }
                        reverse(y.begin(), y.end());
                        for(int l = 0; l < k - j; l++){
                            r[l + i + 1] = y[l];
                        }
                        for(int l = 0; l < j - i; l++){
                            r[l + i + k - j + 1] = x[l];
                        }
                    }
                    if(dis[r[i]][r[i + 1]] + dis[r[j]][r[j + 1]] + dis[r[k]][r[k + 1]] >
                       dis[r[i]][r[j]] + dis[r[j + 1]][r[k + 1]] + dis[r[k]][r[i + 1]]){
                        vector<int> x(j - i), y(k - j);
                        for(int l = 0; l < j - i; l++){
                            x[l] = r[l + i + 1];
                        }
                        for(int l = 0; l < k - j; l++){
                            y[l] = r[l + j + 1];
                        }
                        reverse(x.begin(), x.end());
                        reverse(y.begin(), y.end());
                        for(int l = 0; l < j - i; l++){
                            r[l + i + 1] = x[l];
                        }
                        for(int l = 0; l < k - j; l++){
                            r[l + j + 1] = y[l];
                        }
                    }
                    if(dis[r[i]][r[i + 1]] + dis[r[j]][r[j + 1]] + dis[r[k]][r[k + 1]] >
                       dis[r[i]][r[j + 1]] + dis[r[j]][r[k]] + dis[r[k + 1]][r[i + 1]]){
                        vector<int> x(j - i), y(k - j);
                        for(int l = 0; l < j - i; l++){
                            x[l] = r[l + i + 1];
                        }
                        for(int l = 0; l < k - j; l++){
                            y[l] = r[l + j + 1];
                        }
                        reverse(x.begin(), x.end());
                        for(int l = 0; l < k - j; l++){
                            r[l + i + 1] = y[l];
                        }
                        for(int l = 0; l < j - i; l++){
                            r[l + i + k - j + 1] = x[l];
                        }
                    }
                }
            }
        }
    }
    if((int)r.size() == 2){
        cout << -1 << endl;
        return 1;
    }
    int res = 0;
    for(int i = 0; i < (int)r.size() - 1; i++){
        res += dis[r[i]][r[i + 1]];
    }
    if(res <= restt){
        fill(der, der + n, 0);
        for(int i = 0; i < (int)r.size() - 1; i++) go(r[i], r[i + 1]);
        return res;
    }
    else{
        int rt = 0;
        for(int i = 0; i < (int)r.size() - 1; i++){
            if(rt + dis[r[i]][r[i + 1]] < restt){
                rt += go(r[i], r[i + 1]);;
            }
            else{
                for(int i = 0; i < restt - rt; i++) cout << -1 << endl;
                return restt;
            }
        }
    }
    return restt;
}

int main()
{
    int m;
    cin >> n >> m;
    int u[1000], v[1000], d[1000];
    vector<P> g[500];
    for(int i = 0; i < m; i++){
        cin >> u[i] >> v[i] >> d[i];
        u[i]--;
        v[i]--;
        g[u[i]].push_back(P(v[i], d[i]));
        g[v[i]].push_back(P(u[i], d[i]));
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) dis[i][j] = INF;
    }
    for(int i = 0; i < n; i++){
        priority_queue<P, vector<P>, greater<P>> que;
        dis[i][i] = 0;
        pre[i][i] = -1;
        que.push(P(0, i));
        while(que.size()){
            P nowp = que.top();
            que.pop();
            int now = nowp.second;
            if(dis[i][now] < nowp.first) continue;
            for(P nextp : g[now]){
                int next = nextp.first;
                int cost = nextp.second;
                if(dis[i][next] > dis[i][now] + cost){
                    dis[i][next] = dis[i][now] + cost;
                    pre[i][next] = now;
                    que.push(P(dis[i][next], next));
                }
            }
        }
    }
    int t;
    cin >> t;
    int b[10002];
    fill(b, b + t + 1, -1);
    for(int i = 0; i < t; i++){
        int nw;
        cin >> nw;
        if(nw == 1){
            int id, dst;
            cin >> id >> dst;
            b[i] = dst - 1;
        }
    }
    int lastt = -1;
    int nowt = 0;
    while(nowt < t){
        for(int i = lastt + 1; i <= nowt; i++) if(b[i] != -1) der[b[i]]++;
        lastt = nowt;
        nowt += roop(t - nowt);
    }
}

Measured memory_bytes: 1920