# include "bits/stdc++.h"
using namespace std;
using LL = long long;
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
# define FOR(i,tptpt,ypypy)   for(int i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

vector<pair<int, int>> Graph[404];//to, cost
LL Destination[404][404];
LL V, E;
LL T_max;

class xor_shift_128 {
public:
    typedef uint32_t result_type;
    xor_shift_128(uint32_t seed = 42) {
        set_seed(seed);
    }
    void set_seed(uint32_t seed) {
        a = seed = 1812433253u * (seed ^ (seed >> 30));
        b = seed = 1812433253u * (seed ^ (seed >> 30)) + 1;
        c = seed = 1812433253u * (seed ^ (seed >> 30)) + 2;
        d = seed = 1812433253u * (seed ^ (seed >> 30)) + 3;
    }
    uint32_t operator() () {
        uint32_t t = (a ^ (a << 11));
        a = b; b = c; c = d;
        return d = (d ^ (d >> 19)) ^ (t ^ (t >> 8));
    }
    static constexpr uint32_t max() { return numeric_limits<result_type>::max(); }
    static constexpr uint32_t min() { return numeric_limits<result_type>::min(); }
private:
    uint32_t a, b, c, d;
};

void dijkstra(int start) {
	for (int i = 0; i < V; i++)Destination[start][i] = HINF<int>();
	priority_queue<pair<int, int>, std::vector<pair<int, int>>, std::greater<pair<int, int>>> pq;
	Destination[start][start] = 0;
	pq.push(make_pair(Destination[start][start], start));//cost,to
	while (!pq.empty()) {
		pair<int, int> p = pq.top();
		pq.pop();
		int i = p.second;
		if (Destination[start][i] < p.first)continue;
		for (int k = 0; k < (int)Graph[i].size(); k++) {
			pair<int, int> e = Graph[i][k];
			if (Destination[start][e.first] <= Destination[start][i] + e.second)continue;
			Destination[start][e.first] = Destination[start][i] + e.second;
			pq.push(make_pair(Destination[start][e.first], e.first));
		}
	}
}

struct track_data{
    bool on_vertex;
    int current;
    int from, to, destination, position;
    track_data(){
        on_vertex = true;
        current = 0;
        from = to = destination = position = -1;
    }
};

map<int, pair<int, int>> ids;
set<int> informations, loading;

pair<pair<int, int>, bool> opt_order[404];
xor_shift_128 gen;
LL predict_calculation(int first, int penalty, int start){
    int opt_size = 0;
    for(auto id : loading){
        opt_order[opt_size].first = ids[id];
        opt_order[opt_size].second = false;
        opt_size++;
        if(opt_size > 400)break;
    }
    if(240 <= start && start <= 250)cerr << opt_size;
    if(opt_size == 0){
        if(240 <= start && start <= 250)cerr << " score = " << T_max * T_max - (LL)(penalty + Destination[first][0])*(LL)(penalty + Destination[first][0]) << endl;
        return T_max * T_max - (LL)(penalty + Destination[first][0])*(LL)(penalty + Destination[first][0]);
    }
    if(opt_size == 1){
        int to = opt_order[0].first.first;
        int orderd = opt_order[0].first.second;
        return T_max * T_max - (LL)(start + Destination[first][to] - orderd)*(LL)(start + Destination[first][to] - orderd);
    }
    int last_improved = 0;
    LL ret = -HINF<LL>();
    int attempt = 0;
    while(last_improved <= 50 && attempt <= 500){
        attempt++;
        last_improved++;
        int u, v;
        bool flg = false;
        do{
            flg = false;
            u = uniform_int_distribution<int>(0, opt_size - 1)(gen);
            v = uniform_int_distribution<int>(0, opt_size - 1)(gen);
            int zeropos = 0;
            while(opt_order[zeropos].first.first != 0)zeropos++;
            if(u > v)swap(u, v);
            if(opt_order[u].first.second == false && opt_order[v].first.second == true)flg = true;
        }while(u == v || flg);
        swap(opt_order[u], opt_order[v]);

        LL num = 0;
        LL deliverd = start;
        REP(i, opt_size){
            int cur = opt_order[i].first.first;
            LL orderd = opt_order[i].first.second;
            if(i == 0){
                deliverd += penalty;
                num += T_max * T_max - (LL)(deliverd - orderd) * (LL)(deliverd - orderd);
            }else{
                int pre = opt_order[i - 1].first.first;
                deliverd += Destination[pre][cur];
                num += T_max * T_max - (LL)(deliverd - orderd) * (LL)(deliverd - orderd);
            }
        }

        if(ret < num){
            ret = num;
            last_improved = 0;
        }else{
            swap(opt_order[u], opt_order[v]);
        }
    }
    return ret;
}

int delpool[404];

void solve(){

    //全頂点間の最短距離
    REP(i, V){
        dijkstra(i);
    }

    track_data track;
    REP(iteration, T_max){
        //if(iteration >= 250)break;
        // 注文情報（入力）
        {
            int N_new;
            cin >> N_new;
            int id, dst;
            REP(i, N_new){
                cin >> id >> dst;
                dst--;
                ids[id] = make_pair(dst, iteration);
                informations.insert(id);
            }
        }
        //荷物回収処理（なし）
        {
            if(track.on_vertex && track.current != 0){
                int idx = 0;
                for(auto it : ids){
                    if(it.second.first == track.current){
                        delpool[idx] = it.first;
                        idx++;
                    }
                }
                REP(i, idx)loading.erase(delpool[i]);
            }
            if(track.on_vertex && track.current == 0){
                for(auto st : informations){
                    loading.insert(st);
                }
                informations.clear();   
            }
        }
        //行動探索（出力）
        {
            int ans = -1;
            LL max_predict = 0;
            if(track.on_vertex){
                for(auto to : Graph[track.current]){
                    LL num = predict_calculation(to.first, to.second, iteration);
                    //if(240 <= iteration && iteration <= 250)cerr << "[debug]iteration = " << iteration << " : predict_calculation(" << to.first << ") = " << num << endl;
                    if(max_predict < num){
                        ans = to.first;
                        max_predict = num;
                    }
                }
            }else{
                LL num = predict_calculation(track.to, track.destination - track.position, iteration);
                //if(240 <= iteration && iteration <= 250)cerr << "[debug]iteration = " << iteration << " : predict_calculation(" << track.to << ") = " << num << "penalty = " << track.destination - track.position << endl;
                if(max_predict < num){
                    ans = track.to;
                    max_predict = num;
                }
                num = predict_calculation(track.from, track.position, iteration);
                //if(240 <= iteration && iteration <= 250)cerr << "[debug]iteration = " << iteration << " : predict_calculation(" << track.from << ") = " << num << "penalty = " << track.position << endl;
                if(max_predict < num){
                    ans = track.from;
                    max_predict = num;
                }
            }
            cout << (ans == -1 ? -1 : ans + 1) << endl;
            if(ans != -1){
                if(track.on_vertex){
                    track.on_vertex = false;
                    track.from = track.current;
                    track.to = ans;
                    int num = 0;
                    for(auto to : Graph[track.current]){
                        if(to.first == ans){
                            num = to.second;
                        }
                    }
                    track.destination = num;
                    track.position = 1;
                    track.current = -1;
                }else{
                    if     (ans == track.to)  track.position++;
                    else if(ans == track.from)track.position--;
                }

                if(track.position == 0 || track.position == track.destination){
                    track.on_vertex = true;
                    track.current = (track.position == 0 ? track.from : track.to);
                    track.from = -1, track.to = -1, track.destination = -1, track.position = -1;
                }
            }
        }
        /*
        //エラーチェック（入力）
        {
            string verdict;
            cin >> verdict;
            if(verdict != "OK")return;
        }
        //完了した注文情報（入力）
        {
            int N_achieve;
            cin >> N_achieve;
            int num;
            REP(i, N_achieve){
                cin >> num;
            }
        }
        */
        //cerr << "[debug]finished iteration " << iteration << endl;
    }
}

void input_graph(){
    INIT;
    cin >> V >> E;
    int u, v, d;
    REP(i, E){
        cin >> u >> v >> d;
        u--, v--;
        Graph[u].emplace_back(make_pair(v, d));
        Graph[v].emplace_back(make_pair(u, d));
    }
    cin >> T_max;
}

int main(){
    INIT;
    input_graph();
    cerr << "[debug]finished input_graph()" << endl;
    solve();
    cerr << "[debug]finished solve()" << endl;
}

Measured memory_bytes: 2304