#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <tuple>
#include <algorithm>
using namespace std;

template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;
using ll = long long;

enum class Type {
    NOMAL, RETURN
};

struct Timer
{
    const double CYCLE_PER_SEC = 2800000000.0;
    unsigned long long BEGIN_CYCLE = 0;
    Timer() {}
    unsigned long long int getCycle() {
        unsigned int low, high;
        __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
        return ((unsigned long long int)low) | ((unsigned long long int)high << 32);
    }
    void start(void) {
        BEGIN_CYCLE = getCycle();
    }
    double get_time(void) {
        return (double)(getCycle() - BEGIN_CYCLE) / CYCLE_PER_SEC;
    }
};

struct XorShift
{
    unsigned int x;
    XorShift () : x(2463534242U) {}
    unsigned int rand() {
        x ^= (x << 13);
        x ^= (x >> 17);
        x ^= (x << 5);
        return x;
    }
};

struct Edge
{
    int to;
    ll dist;
    Edge (int _t, ll _d) {
        to = _t;
        dist = _d;
    }
};

struct Info
{
    ll time;
    int new_id;
    int dst;
    Info (ll _t, int _i, int _d) {
        time = _t;
        new_id = _i;
        dst = _d;
    }
};

/*------------------>8------------------->8------------------->8--------------------*/

#define PROBLEM (0)

constexpr ll INF = 1e18;
constexpr double TIME_LIMIT = 25.8;

ll V,E,Tmax;
ll Dist[512][512];
vector<Edge> G[512];
vector<int> Route[512][512];
vector<int> f;

XorShift xorshift;

/*------------------>8------------------->8------------------->8--------------------*/

inline bool accept (double diff, double temp)
{
    if (diff >= 0) return true;
    double diff_log = -sqrt(-diff);
    double P = exp(diff_log / temp) * 4294967295.0;
    return xorshift.rand() < P;
}

inline ll get_dist (vector<Info> &Order)
{
    ll ret = 0;
    for (int i = 0; i < (int)Order.size(); i++) {
        int from = Order[i].dst;
        int to   = Order[(i + 1) % Order.size()].dst;
        ret += Dist[from][to];
    }
    return ret;
}

void traveling_salesman_sa (vector<Info> &Order)
{
    const double TIME_LIMIT_T = TIME_LIMIT * (double)Order.size() / (double)Tmax;
    const double TEMP_START = 1.0;
    const double TEMP_END   = 0.0001;
    const double TEMP_DIFF  = (TEMP_START - TEMP_END) / TIME_LIMIT_T;
    Timer timer;
    timer.start();
    ll cur_score = get_dist(Order);
    ll best_score = cur_score;
    vector<Info> best_order = Order;
    while (true) {
        double cur_time = timer.get_time();
        double cur_temp = TEMP_START - TEMP_DIFF * cur_time;
        if (cur_time > TIME_LIMIT_T) {
            Order = best_order;
            return;
        }
        int idx1 = xorshift.rand() % (Order.size() - 1) + 1;
        int idx2 = xorshift.rand() % (Order.size() - 1) + 1;
        if (idx1 == idx2) continue;
        if (idx1 > idx2) swap(idx1, idx2);
        reverse(Order.begin() + idx1, Order.begin() + idx2 + 1);
        ll nxt_score = get_dist(Order);
        if (accept((double)(cur_score - nxt_score), cur_temp)) {
            cur_score = nxt_score;
        } else {
            reverse(Order.begin() + idx1, Order.begin() + idx2 + 1);
        }
        if (cur_score < best_score) {
            best_score = cur_score;
            best_order = Order;
        }
    }
}

/*------------------>8------------------->8------------------->8--------------------*/

vector<int> get_command (vector<Info> order)
{
    order.insert(order.begin(), Info(0, 0, 1));
    traveling_salesman_sa(order);

    order.push_back(Info(0, 0, 1));
    vector<int> ret;
    for (int i = 0; i < (int)order.size() - 1; i++) {
        int cur_v = order[i].dst;
        int nxt_v = order[i + 1].dst;
        vector<int> rt = Route[cur_v][nxt_v];
        for (int j = 1; j < (int)rt.size(); j++) {
            for (int k = 0; k < Dist[rt[j - 1]][rt[j]]; k++) {
                ret.push_back(rt[j]);
            }
        }
    }
    return ret;
}

vector<Info> get_new_order (ll cur_time)
{
    vector<Info> ret;
    int Nnew;
    cin >> Nnew;
    for (int j = 0; j < Nnew; j++) {
        int id,dst;
        cin >> id >> dst;
        ret.push_back(Info(cur_time, id, dst));
    }
#if PROBLEM
    int Nput;
    cin >> Nput;
    for (int i = 0; i < Nput; i++) {
        int put_id;
        cin >> put_id;
    }
#endif
    return ret;
}

void get_result ()
{
    string verdict;
    cin >> verdict;
    if (verdict == "NG") {
        exit(0);
    }
    int Nachieve;
    cin >> Nachieve;
    for (int i = 0; i < Nachieve; i++) {
        int achieve_id;
        cin >> achieve_id;
    }
}

/*------------------>8------------------->8------------------->8--------------------*/

void initialize ()
{
    for (int i = 0; i < 512; i++) {
        fill(Dist[i], Dist[i] + 512, INF);
        Dist [i][i] = 0;
        Route[i][i] = vector<int>({i});
    }
    for (int from = 1; from <= V; from++) {
        reversed_priority_queue<tuple<ll,int,vector<int>>> que;
        que.emplace(0LL, from, vector<int>({from}));
        while (!que.empty()) {
            ll dt;
            int vt;
            vector<int> rt;
            tie(dt, vt, rt) = que.top();
            que.pop();
            if (Dist[from][vt] < dt) {
                continue;
            }
            for (int i = 0; i < G[vt].size(); i++) {
                ll ndt = dt + G[vt][i].dist;
                int nvt = G[vt][i].to;
                if (Dist[from][nvt] > ndt) {
                    vector<int> nrt = rt;
                    nrt.push_back(nvt);
                    Dist [from][nvt] = ndt;
                    Route[from][nvt] = nrt;
                    que.emplace(ndt, nvt, nrt);
                }
            }
        }
    }
}

int main (int argc, const char * argv[])
{
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        int u,v,d;
        cin >> u >> v >> d;
        G[u].push_back(Edge(v, d));
        G[v].push_back(Edge(u, d));
    }
    
#if PROBLEM
    f.resize(V);
    for (int i = 0; i < V; i++) {
        cin >> f[i];
    }
#endif
    
    cin >> Tmax;
    initialize();
    
    ll cur_time = 0LL;
    vector<int> command;
    while (cur_time < Tmax) {
        vector<Info> order;
        for (auto x: command) {
            cout << x << endl;
#if PROBLEM
            get_result();
#endif
            cur_time++;
            vector<Info> order_t = get_new_order(cur_time);
            for (auto x: order_t) {
                order.push_back(x);
            }
            if (cur_time >= Tmax) {
                return 0;
            }
        }
        while (order.size() == 0) {
            cout << -1 << endl;
#if PROBLEM
            get_result();
#endif
            cur_time++;
            order = get_new_order(cur_time);
            if (cur_time >= Tmax) {
                return 0;
            }
        }
        command = get_command(order);
    }
    
    return 0;
}


Measured memory_bytes: 23168