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

const int INF = 100000000;

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 main()
{
    int n, 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 = 0;
    int nowt = 0;
    int nowp = 0;
    while(true){
        if(nowp == 0 && b[nowt] != -1) der[b[nowt]]++;
        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){
            if(nowp != 0){
                int r = dis[nowp][0];
                if(r > t - nowt){
                    for(int i = 0; i < t - nowt; i++) cout << -1 << endl;
                    break;
                }
                nowt += go(nowp, 0);
                for(int i = lastt + 1; i < nowt; i++){
                    if(b[i] != -1) der[b[i]]++;
                }
                nowp = 0;
            }
            else{
                if(t == nowt) break;
                cout << -1 << endl;
                nowt++;
            }
            lastt = nowt;
        }
        else if(nowp != 0 && near * 7 > (dis[nowp][0] + dis[argnear][0]) * 5){
            int r = dis[nowp][0];
            if(r > t - nowt){
                for(int i = 0; i < t - nowt; i++) cout << -1 << endl;
                break;
            }
            nowt += go(nowp, 0);
            for(int i = lastt + 1; i < nowt; i++){
                if(b[i] != -1) der[b[i]]++;
            }
            nowp = 0;
        }
        else{
            int r = dis[nowp][argnear];
            if(r > t - nowt){
                for(int i = 0; i < t - nowt; i++) cout << -1 << endl;
                break;
            }
            nowt += go(nowp, argnear);
            der[argnear] = 0;
            nowp = argnear;
        }
    }
}

Measured memory_bytes: 1920