#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

int V,E;
vector<vector<pair<int,int>>> G;
int T;
vector<int> Info;
vector<int> atShop;
int allatShop = 0;
int allatCar = 0;
vector<int> atCar;
 
vector<int> ans;

vector<vector<vector<pair<int,int>>>> short_way;
vector<vector<int>> distance_way;

vector<int> go_road;
int go_from = 0;
int go_to = 3;
int go_dist = 0;
int Position = 0;
void dfs(int u, int v, vector<int> ro){
    for (pair<int,int> i : short_way[go_from][u]){
        if(i.first == v) continue;
        vector<int> rod = ro;
        rod.push_back(i.first);
        if(i.first == go_to){
            go_road = rod;
            go_dist = i.second;
            return;
        }
        dfs(i.first,u,rod);
    }
    
}


int main()
{
    
    
    
    //cin
    cin >> V >> E;
    G.resize(V);
    rep(i,E){
        int u,v,d;
        cin >> u >> v >> d;
        u--;v--;
        G[u].push_back(make_pair(v,d));
        G[v].push_back(make_pair(u,d));
    }
    
    cin >> T;
    Info.assign(T,0);
    rep(i,T){
        int N,id,dst;
        cin >> N;
        if(N == 1){
            cin >> id >> dst;
            dst--;
            Info[i] = dst;
        }
    }
    
    //dijkstra
    short_way.resize(V);
    distance_way.assign(V,vector<int>(V,0));
    for (int hh = 0; hh < V; hh++) {
        short_way[hh].resize(V);
        priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> pq;
        vector<bool> f(V, false);
        pq.push({0,{hh,hh}});
        while (!pq.empty()) {
            int u = -1,d = 0,v=0;
            while (!pq.empty()) {
                pair<int,pair<int,int>> pp = pq.top();
                pq.pop();
                if(!f[pp.second.second]){
                    f[pp.second.second] = true;
                    u = pp.second.second;
                    v = pp.second.first;
                    d = pp.first;
                    distance_way[hh][u] = d;
                    short_way[hh][v].push_back({u,d});
                    break;
                }
            }
            if(u == -1) break;
            for (pair<int,int> i : G[u]){
                if(f[i.first]) continue;
                pq.push({i.second+d,{u, i.first}});
            }
        
        }
    }
    
    
    atShop.assign(V,0);
    atCar.assign(V,0);
    allatShop = 0;
    allatCar = 0;
    Position = 0;
    queue<int> move_position;
    
    int moving = 0;
    //move start
    
    
    for (int t = 0; t < T; t++) {
        
        if(Info[t] > 0){
            allatShop++;
            atShop[Info[t]]++;
        }
        
        if(moving != 0){
            moving--;
            if (moving != 0){
                ans.push_back(Position);
                continue;
            }else{
                int cargo = atCar[Position];
                atCar[Position] = 0;
                allatCar -= cargo;
                
                if(!move_position.empty()){
                    moving = distance_way[Position][move_position.front()];
                    Position = move_position.front();
                    move_position.pop();
                    ans.push_back(Position);
                    continue;
                }
            }
        }
        
        if(Position == 0){
            allatCar += allatShop;
            allatShop = 0;
            rep(i,V) atCar[i] += atShop[i], allatShop = 0;
            
            if(allatCar == 0){
                ans.push_back(-1);
                continue;
            }
            if(t < T-1 && Info[t+1]!=0){
                ans.push_back(-1);
                continue;
            }
            
            int next = 1;
            int next_distanve = distance_way[0][1];
            for (int i = 1; i < V; i++) {
                if(atCar[i] != 0){
                    if(next_distanve > distance_way[0][i]) next = i, next_distanve = distance_way[0][i];
                }
            }
            go_from = 0, go_to = next;
            vector<int> fff = {go_from};
            dfs(Position, Position, fff);
            rep(i, int(go_road.size())) move_position.push(go_road[i]);
            move_position.pop();
            moving = distance_way[Position][move_position.front()];
            Position = move_position.front();
            move_position.pop();
            ans.push_back(Position);
            
        }else{
            if(allatCar == 0){
                
                go_from = Position, go_to = 0;
                vector<int> fff = {go_from};
                dfs(Position, Position, fff);
                rep(i, int(go_road.size())) move_position.push(go_road[i]);
                move_position.pop();
                moving = distance_way[Position][move_position.front()];
                Position = move_position.front();
                move_position.pop();
                ans.push_back(Position);
                
            }else{
                
                int next = Position-1;
                int next_distanve = distance_way[Position][Position-1];
                for (int i = 1; i < V; i++) {
                    if(i == Position) continue;
                    if(atCar[i] != 0){
                        if(next_distanve > distance_way[Position][i]) next = i, next_distanve = distance_way[Position][i];
                    }
                }
                go_from = Position, go_to = next;
                vector<int> fff = {go_from};
                dfs(Position, Position, fff);
                rep(i, int(go_road.size())) move_position.push(go_road[i]);
                move_position.pop();
                moving = distance_way[Position][move_position.front()];
                Position = move_position.front();
                move_position.pop();
                ans.push_back(Position);
                
            
            }
        }
        
        
        
        
    }
    
    
    rep(i,T){
        if(ans[i] == -1) cout << ans[i] << endl;
        else cout << ans[i]+1 << endl;
        
    }
    
    
    return 0;
}





Measured memory_bytes: 8576