// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール

// マラソン用モジュール
namespace marathon {
    clock_t start_clock;
    constexpr double time_limit = 29.9; // 実行時間[s]より0.1ms程度余裕をあける
    constexpr double time_limit_inv = 1.0 / time_limit;
    constexpr double CLOCKS_PER_SEC_INV = 1.0 / CLOCKS_PER_SEC;
    inline double nowtime() { return CLOCKS_PER_SEC_INV * (clock() - start_clock); }
    inline bool intime() { return nowtime() < time_limit; }
    inline double progress() { return nowtime() * time_limit_inv; }
    struct preexec_dummy {
        preexec_dummy() {
            start_clock = clock();
        }
    } preexec_dummy_instance;
}

// XORShift 擬似乱数発生器
uint32_t xor128(void){
    static uint32_t x = 123456789;
    static uint32_t y = 362436069;
    static uint32_t z = 521288629;
    static uint32_t w = 88675123; 
    uint32_t t;

    t = x ^ (x << 11);
    x = y; y = z; z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));  
}
inline double rand_uniform(void) { return (double)xor128() / 0x100000000LL; }
template <typename T>
inline T rand_range(T min, T max) { return min + xor128() % (max - min + 1); }
inline bool rand_prob(double p) { return rand_uniform() < p; }

// 辺
struct edge {

    int src, dst, dist;

    edge(): dst(-1), dist(0) {}
    edge(int u, int v, int d) : src(u), dst(v), dist(d) {}

};

// 無向グラフ
struct undirected_graph {

    
    int vertex_num, edge_num;
    vector<edge> el; // 辺リスト
    vector<vector<edge>> gl; // 隣接リスト
    vector<vector<int>> gm; // 隣接行列
    vector<vector<int>> dm; // 距離行列

    undirected_graph() :
        vertex_num(0), edge_num(0),
        el(), gl(), gm() {}
    undirected_graph(const vector<edge> &_el) : el(_el)
    {
        vertex_num = 1 + accumulate(ALL_OF(el), 0, [](int ac, edge &e) { return max({ac, e.src, e.dst}); });
        edge_num = el.size();
        gl = vector<vector<edge>>(vertex_num);
        gm = vector<vector<int>>(vertex_num, vector<int>(vertex_num, INF));
        for (edge &e : el) {
            gm[e.src][e.dst] = gm[e.dst][e.src] = e.dist;
            gl[e.src].emplace_back(e);
            gl[e.dst].emplace_back(e.dst, e.src, e.dist);
        }
        
        // Warshall-Floyd O(|E|^3)
        dm = gm;
        REP(k, vertex_num) REP(i, vertex_num) REP(j, vertex_num) {
            if (dm[i][k] < INF && dm[k][j] < INF) {
                chmin(dm[i][j], dm[i][k] + dm[k][j]);
            }
        }
    }

    inline int distance(int u, int v) const {
        assert(0 <= u && u < vertex_num);
        assert(0 <= v && v < vertex_num);
        return dm[u][v];
    }

};

// 注文
struct order {
    int id, t0, dst;
    order() : id(-1), t0(INF), dst(-1) {}
    order(int i, int t, int u) : id(i), t0(t), dst(u) {}
};

// 注文データ
struct order_data {
    vector<order> o;
    order_data() : o() {}
    order_data(const vector<order> &_ol) : o(_ol) {
        sort(ALL_OF(o), [](order &o, order &p) {
            return o.t0 < p.t0 || (o.t0 == p.t0 && o.id < p.id);
        });
    }
};

// 入力
struct input_data {

    undirected_graph g;
    int tmax = 10000;
    order_data o;

    input_data() : g() {}
    input_data(istream &ist) {

        // 空間情報
        int v, e; ist >> v >> e;
        vector<edge> el;
        REP(i, e) {
            int u, v, d;
            ist >> u >> v >> d;
            u--; v--; // 0-indexed
            el.emplace_back(u, v, d);
        }
        g = undirected_graph(el);

        // 時間と注文データ
        ist >> tmax; // assert(tmax == 10000);
        vector<order> ol;
        REP(t0, tmax) {
            int nnew; ist >> nnew;
            REP(j, nnew) {
                int new_id, dst; ist >> new_id >> dst;
                ol.emplace_back(new_id, t0, dst);
            }
        }
        o = order_data(ol);

    }

};
// どうせ入力一つだけやしグローバルでもええやろ
input_data inp;

// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    inp = input_data(cin);

    int x = 0, y = 0, p = 0;
    vector<int> ans(inp.tmax);
    REP(t, inp.tmax) {
        if (p <= 0) {
            x = y;
            const auto &candlist = inp.g.gl[x];
            vector<int> rank(candlist.size());
            iota(ALL_OF(rank), 0);
            sort(ALL_OF(rank), [&](int &i, int &j) {
                return candlist[i].dist < candlist[j].dist;
            });
            const auto &cand = candlist[(int)(pow(rand_uniform(), 2.0) * candlist.size())];
            y = cand.dst;
            p = cand.dist;
        }
        ans[t] = y;
        p--;
    }

    REP(t, inp.tmax) cout << ans[t] + 1 << endl;
    
}

Measured memory_bytes: 1792