#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);
        }
    }
    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 nowp = 0;
        int rt = 0;
        while(true){
            int near = INF;
            int argnear = -1;
            for(int i = 0; i < n; i++){
                if(der[i] != 0 && dis[nowp][i] < near){
                    near = dis[nowp][i];
                    argnear = i;
                }
            }
            if(argnear == -1){
                for(int i = 0; i < restt - rt; i++) cout << -1 << endl;
                return restt;
            }
            else{
                int s = dis[nowp][argnear];
                if(s > restt - rt){
                    for(int i = 0; i < restt - rt; i++) cout << -1 << endl;
                    return restt;
                }
                rt += go(nowp, argnear);
                der[argnear] = 0;
                nowp = argnear;
            }
        }
    }
}

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