#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <tuple>
#include <algorithm>
#include <set>
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 (1)

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;

int CurVertex;
vector<Info> DepotOrder;
vector<Info> TruckOrder;
queue<int> CommandQueue;

XorShift xorshift;

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

int get_nxt_vertex ()
{
    set<int> v_cnd;
    for (int i = 0; i < TruckOrder.size(); i++) {
        v_cnd.insert(TruckOrder[i].dst);
    }
    vector<tuple<ll,int>> cnd;
    for (int i = 0; i < TruckOrder.size(); i++) {
        ll dt = Dist[CurVertex][TruckOrder[i].dst];
        cnd.push_back(make_tuple(dt, TruckOrder[i].dst));
    }
    if (DepotOrder.size() > 5) {
        cnd.push_back(make_tuple(Dist[CurVertex][1], 1));
    }
    sort(cnd.begin(), cnd.end());
    int nxt_v = get<1>(cnd.front());
    return nxt_v;
}

void push_new_command (ll cur_time)
{
    for (int i = 0; i < TruckOrder.size(); i++) {
        if (TruckOrder[i].dst == CurVertex) {
            TruckOrder.erase(TruckOrder.begin() + i);
            i--;
        }
    }
    if (DepotOrder.size() > 0 && CurVertex == 1) {
        for (auto x: DepotOrder) {
            TruckOrder.push_back(x);
        }
        DepotOrder.clear();
    }
    if (TruckOrder.size() == 0 && CurVertex == 1) {
        CommandQueue.push(-1);
        return;
    }
    if (TruckOrder.size() == 0 && CurVertex != 1) {
        vector<int> rt = Route[CurVertex][1];
        CurVertex = 1;
        for (int i = 0; i < (int)rt.size() - 1; i++) {
            for (int j = 0; j < Dist[rt[i]][rt[i + 1]]; j++) {
                CommandQueue.push(rt[i + 1]);
            }
        }
        return;
    }
    int nxt_v = get_nxt_vertex();
    vector<int> rt = Route[CurVertex][nxt_v];
    CurVertex = nxt_v;
    for (int i = 0; i < (int)rt.size() - 1; i++) {
        for (int j = 0; j < Dist[rt[i]][rt[i + 1]]; j++) {
            CommandQueue.push(rt[i + 1]);
        }
    }
}

/*------------------>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);
                }
            }
        }
    }
    CurVertex = 1;
}

void problem_a_get_new_order (ll cur_time)
{
    int Nnew;
    cin >> Nnew;
    for (int i = 0; i < Nnew; i++) {
        int new_id,dst;
        cin >> new_id >> dst;
        DepotOrder.push_back(Info(cur_time, new_id, dst));
    }
}

void problem_b_get_new_order (ll cur_time)
{
    int Nnew;
    cin >> Nnew;
    for (int i = 0; i < Nnew; i++) {
        int new_id,dst;
        cin >> new_id >> dst;
        DepotOrder.push_back(Info(cur_time, new_id, dst));
    }
    int Nput;
    cin >> Nput;
    for (int i = 0; i < Nput; i++) {
        int put_id;
        cin >> put_id;
    }
}

void problem_b_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--------------------*/

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;
    while (cur_time < Tmax) {
#if PROBLEM
        problem_b_get_new_order(cur_time);
#else
        problem_a_get_new_order(cur_time);
#endif
        if (CommandQueue.empty()) {
            push_new_command(cur_time);
        }
        cout << CommandQueue.front() << endl;
        CommandQueue.pop();
        cur_time++;
#if PROBLEM
        problem_b_get_result();
#endif
    }

    return 0;
}


Measured memory_bytes: 23628