#include <bits/stdc++.h>
using namespace std;

mt19937 rnd;
uniform_real_distribution<> dist01(0.0, 1.0);
double rnd01(){ return dist01(rnd);}

const double TIME_LIMIT = 29500;
double elapsed;
chrono::system_clock::time_point t_start;
void update_time(){
    auto t_now = chrono::system_clock::now();
    elapsed = chrono::duration_cast<chrono::milliseconds>(t_now - t_start).count();
}
bool timeover(){ return (elapsed > TIME_LIMIT);}

void chmin(int& a, int b){
    a = min(a, b);
}

const int Tmax = 10000;
int N, M, Dst[Tmax];
int dist[400][400], E[400][400], Nxt[400][400], Total;

void initialize(){
    t_start = chrono::system_clock::now();
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        E[a][b] = E[b][a] = c;
    }
    int _; cin >> _;
    for(int i=0; i<Tmax; i++){
        int n; cin >> n;
        if(n) cin >> _ >> Dst[i];
        Dst[i]--;
        Total += n;
    }

    for(int i=0; i<N; i++) for(int j=0; j<N; j++) if(i != j) dist[i][j] = (E[i][j] ? E[i][j] : 1e9);
    for(int k=0; k<N; k++) for(int i=0; i<N; i++) for(int j=0; j<N; j++) chmin(dist[i][j], dist[i][k] + dist[k][j]);
    for(int i=0; i<N; i++) for(int j=0; j<N; j++){
        for(int k=0; k<N; k++) if(i != k && E[i][k] && E[i][k] + dist[k][j] == dist[i][j]){
            Nxt[i][j] = k;
            break;
        }
    }
}

struct Status{
    vector<pair<int, int>> ans;
    vector<vector<int>> stock, have;
    int pos, now, stocksum, havesum;
    int64_t score;
    int scorenum;
    Status():
    stock(N), have(N), pos(0), now(0), stocksum(0), havesum(0),
    score(0), scorenum(0){}
    bool operator<( const Status& right ) const {
        return score < right.score;
    }
    bool operator>( const Status& right ) const {
        return score > right.score;
    }
};

void addtime(Status& st){
    if(st.now < Tmax && Dst[st.now] >= 0){
        st.stocksum++;
        st.stock[Dst[st.now]].push_back(st.now);
    }
    st.now++;
}
void visit(int v, Status& st){
    if(st.now > Tmax) return;
    if(v == 0) for(int i=0; i<N; i++){
        for(int a : st.stock[i]) st.have[i].push_back(a);
        st.stocksum -= st.stock[i].size();
        st.havesum += st.stock[i].size();
        st.stock[i].clear();
    }
    for(int a : st.have[v]) st.score += Tmax*Tmax - (st.now-a)*(st.now-a);
    st.scorenum += st.have[v].size();
    st.havesum -= st.have[v].size();
    st.have[v].clear();
}

void moveto(int v, Status& st){
    if(st.pos == v){
        addtime(st);
        if(st.ans.size() && st.ans.back().first == -1){
            st.ans.back().second++;
        }else{
            st.ans.emplace_back(-1, 1);
        }
        visit(st.pos, st);
        return;
    }
    while(st.pos != v){
        int nxt = Nxt[st.pos][v];
        int d = E[st.pos][nxt];
        bool leave = false;
        for(int k=0; k<d; k++){
            addtime(st);
            if(!leave) visit(st.pos, st);
            leave = true;
        }
        st.ans.emplace_back(nxt, d);
        st.pos = nxt;
        visit(nxt, st);
    }
}

int main(){
    initialize();

    vector<Status> que[2];
    Status start;
    que[0].push_back(start);

    int WIDTH = 100 * 400 / N, T = 10;
    for(int t=1; t<=T; t++){
        int width = (t == T ? 1 : WIDTH);
        int term  = (t == T ? Tmax : Tmax * t / T);

        for(auto& p : que[1-t%2]) for(int k=0; k<10; k++){
            auto st = p;
            while(st.now < term){
                if(st.havesum <= 10 || (st.stocksum/max(dist[st.pos][0], 1) >= 3)){
                    moveto(0, st);
                    continue;
                }
                vector<pair<double, int>> eff(N);
                for(int i=0; i<N; i++){
                    if(eff[i].first > 0) continue;
                    int p = st.pos, tm = st.now;
                    double sum = 0;
                    while(p != i){
                        tm += E[p][Nxt[p][i]];
                        if(tm >= Tmax) break;
                        p = Nxt[p][i];
                        for(int a : st.have[p]) sum += Tmax*Tmax - (tm-a)*(tm-a);
                        eff[p] = {sum / (tm-st.now), p};
                    }
                }
                sort(eff.rbegin(), eff.rend());
                int nxt = eff[rnd()%3].second;
                moveto(nxt, st);
            }
            que[t%2].push_back(st);
        }
        que[1-t%2].clear();
        sort(que[t%2].rbegin(), que[t%2].rend());
        if((int)que[t%2].size() > width) que[t%2].resize(width);
    }

    Status opt_status = que[T%2][0];
    update_time();

    int cnt = 0;
    for(auto p : opt_status.ans) for(int k=0; k<p.second; k++){
        if(cnt == Tmax) break;
        cnt++;
        cout << (p.first == -1 ? -1 : p.first+1) << endl;
    }
    
    cerr << "score:        " << opt_status.score << endl;
    cerr << "deliver num:  " << opt_status.scorenum << " / " << Total << " (" << double(opt_status.scorenum)/Total << ")" << endl;
    cerr << "average:      " << opt_status.score / opt_status.scorenum << endl;
    cerr << "for perfect:  " << (opt_status.score / (double(Tmax)*Tmax*Total)) << endl;
    cerr << "elapsed time: " << elapsed << endl;
}


Measured memory_bytes: 80312