#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <tuple>
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;
    int dist;
    Edge (int _t, int _d) {
        to = _t;
        dist = _d;
    }
};

struct Info
{
    int time;
    int new_id;
    int dst;
    Type type;
    Info (int _t, int _i, int _d) {
        time = _t;
        new_id = _i;
        dst = _d;
        type = Type::NOMAL;
    }
};

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

constexpr int INF = 1e9;
constexpr double TIME_LIMIT = 1.8;
constexpr double TEMP_START = 4.0;
constexpr double TEMP_END   = 0.001;
constexpr double TEMP_DIFF  = (TEMP_START - TEMP_END) / TIME_LIMIT;
constexpr int SWAP_RANGE = 10;

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

ll Score;
ll BestScore;
vector<Info> BestOrder;

Timer timer;
XorShift xorshift;

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

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

ll get_score ()
{
    ll ret_score = 0;
    ll cur_v = 1;
    ll cur_time = 0;
    ll nxt_time = 0;
    for (int i = 0; i < Order.size(); i++) {
        if (Order[i].time > cur_time) {
            nxt_time += Dist[cur_v][1];
            if (Order[i].time > nxt_time) {
                nxt_time = Order[i].time;
            }
            cur_v = 1;
            cur_time = nxt_time;
            Order[i].type = Type::RETURN;
        } else {
            Order[i].type = Type::NOMAL;
        }
        ll nxt_v = Order[i].dst;
        nxt_time += Dist[cur_v][nxt_v];
        if (nxt_time > Tmax) {
            return ret_score;
        }
        ll waiting_time = nxt_time - Order[i].time;
        ret_score += Tmax * Tmax - waiting_time * waiting_time;
        cur_v = nxt_v;
    }
    return ret_score;
}

void simulated_annealing ()
{
    while (true) {
        static int itr = 0; itr++;
        static int acp = 0;
        double cur_time = timer.get_time();
        double cur_temp = TEMP_START - TEMP_DIFF * cur_time;
        if (cur_time > TIME_LIMIT) {
            cerr << "Itr    = " << itr << endl;
            cerr << "Accept = " << acp << endl;
            cerr << "Score  = " << BestScore << endl;
            return;
        }
        int idx1 = xorshift.rand() % Order.size();
        int idx2 = idx1 + xorshift.rand() % SWAP_RANGE - SWAP_RANGE / 2;
        if (idx2 < 0            ) idx2 = 0;
        if (idx2 >= Order.size()) idx2 = (int)Order.size() - 1;
        if (idx1 == idx2) continue;
        swap(Order[idx1], Order[idx2]);
        ll st = get_score();
        if (accept((double)st - Score, cur_temp)) {
            acp++;
            Score = st;
        } else {
            swap(Order[idx1], Order[idx2]);
        }
        if (BestScore < Score) {
            BestScore = Score;
            BestOrder = Order;
        }
    }
}

/*------------------>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<int,int,vector<int>>> que;
        que.emplace(0, from, vector<int>({from}));
        while (!que.empty()) {
            int dt,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++) {
                int 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);
                }
            }
        }
    }
    Score = get_score();
    BestScore = Score;
    BestOrder = Order;
}

vector<int> get_command ()
{
    vector<int> ret;
    ll cur_v = 1;
    ll cur_time = 0;
    ll nxt_time = 0;
    for (int i = 0; i < BestOrder.size(); i++) {
        if (BestOrder[i].time > cur_time) {
            vector<int> rt = Route[cur_v][1];
            for (int j = 0; j < (int)rt.size() - 1; j++) {
                ll dt = Dist[rt[j]][rt[j + 1]];
                for (int k = 0; k < dt; k++) {
                    ret.push_back(rt[j + 1]);
                    if (ret.size() >= Tmax) {
                        return ret;
                    }
                }
            }
            nxt_time += Dist[cur_v][1];
            if (Order[i].time > nxt_time) {
                ll add_wait = Order[i].time - nxt_time;
                for (int j = 0; j < add_wait; j++) {
                    ret.push_back(-1);
                    if (ret.size() >= Tmax) {
                        return ret;
                    }
                }
                nxt_time = Order[i].time;
            }
            cur_v = 1;
            cur_time = nxt_time;
        }
        ll nxt_v = Order[i].dst;
        vector<int> rt = Route[cur_v][nxt_v];
        for (int j = 0; j < (int)rt.size() - 1; j++) {
            ll dt = Dist[rt[j]][rt[j + 1]];
            for (int k = 0; k < dt; k++) {
                ret.push_back(rt[j + 1]);
                if (ret.size() >= Tmax) {
                    return ret;
                }
            }
        }
        nxt_time += Dist[cur_v][nxt_v];
        cur_v = nxt_v;
    }
    return ret;
}

int main (int argc, const char * argv[])
{
    timer.start();
    
    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));
    }
    
    cin >> Tmax;
    for (int i = 0; i < Tmax; i++) {
        int Nnew;
        cin >> Nnew;
        for (int j = 0; j < Nnew; j++) {
            int id,dst;
            cin >> id >> dst;
            Order.push_back(Info(i, id, dst));
        }
    }
    
    initialize();
    simulated_annealing();
    
    vector<int> command = get_command();
    for (auto x: command) {
        cout << x << endl;
    }
    
    return 0;
}


Measured memory_bytes: 21248