#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <memory>

#define ALL(a)  (a).begin(),(a).end()

using namespace std;

int cost[400][400];
int lowestCost[400][400];
int nextV[400][400];

int V, E;

long long Tmax;
vector<int> orderedTime;
vector<int> orderedNo;
vector<int> orderedDst;

const int INF = INT_MAX;
const int TRY_N_SUB = 500;
const int WAIT_SIZE = 30;

int updateOrders(int beforeTime, int nowTime, vector<int>& ords);
long long calcSubLoss(const int startTime, const vector<int>& indices) {
    long long loss = 0;
    int curV = 0;
    int curTime = startTime;
    for (const int i : indices) {
        int vi = orderedDst[i];
        curTime += lowestCost[curV][vi];
        curV = vi;
        long long waiting0 = startTime - orderedTime[i];
        long long waiting = curTime - orderedTime[i];
        long long score0 = max(0LL, Tmax*Tmax - waiting0*waiting0);
        long long score = max(0LL, Tmax*Tmax - waiting*waiting);
        loss += score0 - score;
    }
    curTime += lowestCost[curV][0];
    vector<int> orders;
    updateOrders(startTime, curTime, orders);
    for (const int o : orders) {
        long long waiting = curTime - orderedTime[o];
        loss += waiting * waiting;
    }
    return loss;
}
void calcPath(const int startTime, vector<int>& ord_indices) {
    if (ord_indices.size() < 8) {
        // find opt
        sort(ALL(ord_indices));
        long long minLoss = 0;
        vector<int> answer;
        do {
            long long loss = calcSubLoss(startTime, ord_indices);
            if (minLoss > loss) {
                minLoss = loss;
                answer = ord_indices;
            }
        } while (next_permutation(ALL(ord_indices)));
        answer.swap(ord_indices);
        return;
    }
    int curV = 0;
    const auto begin = ord_indices.begin();
    for (int i=0; i<ord_indices.size(); i++) {
        auto bestIter = min_element(
            begin + i,
            ord_indices.end(),
            [&](int a, int b){
                int va = orderedDst[a];
                int vb = orderedDst[b];
                int acost = lowestCost[curV][va];
                int bcost = lowestCost[curV][vb];
                return acost < bcost;
            });
        curV = orderedDst[*bestIter];
        int tmp = *bestIter;
        *bestIter = ord_indices[i];
        ord_indices[i] = tmp;
    }

    if (ord_indices.size() <= 1) return;

    long long loss = calcSubLoss(startTime, ord_indices);
    for (int i=0; i<TRY_N_SUB; i++) {
        int swap0 = rand() % (ord_indices.size()-1); // 前N-1個
        int swap1 = 1 + rand() % (ord_indices.size()-1); // 後ろN-1個
        if (swap0 > swap1) {
            int tmp = swap0;
            swap0 = swap1;
            swap1 = tmp;
        }
        // assert(swap0 <= swap1 < size)

        if (swap0 == swap1) {
            // assert(swap0 == swap1 > 0)
            swap0--;
        }

        swap(ord_indices[swap0], ord_indices[swap1]);
        //reverse(begin+swap0, begin+swap1+1);
        long long lossX = calcSubLoss(startTime, ord_indices);
        if (lossX > loss) {
            swap(ord_indices[swap0], ord_indices[swap1]);
            //reverse(begin+swap0, begin+swap1+1);
        }
        else loss = lossX;
    }
}

void input() {
    for (int i=0; i<400; i++) {
        for (int j=0; j<400; j++) {
            if (i == j) cost[i][j] = 0;
            else cost[i][j] = INF;
        }
    }

    cin >> V >> E;
    for (int i=0; i<E; i++) {
        int u,v,d;
        cin >> u >> v >> d;
        cost[u-1][v-1] = d;
        cost[v-1][u-1] = d;
    }
    
    cin >> Tmax;
    for (int i=0; i<Tmax; i++) {
        int Nnew;
        cin >> Nnew;
        for (int j=0; j<Nnew; j++) {
            int newid, d;
            cin >> newid >> d;
            orderedNo.push_back(newid);
            orderedDst.push_back(d-1);
            orderedTime.push_back(i);
        }
    }
}

void makeCostMap() {
    for (int i=0; i<400; i++) {
        for (int j=0; j<400; j++) {
            lowestCost[i][j] = cost[i][j];
        }
    }

    for (int i=0; i<400; i++) {
        for (int j=0; j<400; j++) {
            if (cost[i][j] != INF) nextV[i][j] = j;
            else nextV[i][j] = -1;
        }
    }

    for (int i=0; i<400; i++) {
        for (int j=0; j<400; j++) {
            for (int k=0; k<400; k++) {
                if (lowestCost[j][i] != INF && lowestCost[i][k] != INF
                    && lowestCost[j][k] > lowestCost[j][i] + lowestCost[i][k]) {
                    lowestCost[j][k] = lowestCost[j][i] + lowestCost[i][k];
                    nextV[j][k] = nextV[j][i];
                }
            }
        }
    }

    // for (int i=0; i<400; i++) {
    //     for (int j=0; j<400; j++) {
    //         if (lowestCost[i][j] == INF) {
    //             cerr << "[cost]could not go to " <<j << "from "<< i << "!" << endl;
    //         }
    //         if (nextV[i][j] == -1)
    //             cerr << "could not go to " <<j << "from "<< i << "!" << endl;
    //         else if (cost[i][nextV[i][j]] == INF)
    //             cerr << "invalid nextV!" << endl;
    //     }
    // }
}

void filterOrders() {
    vector<int> orderedTime_;
    vector<int> orderedDst_;
    vector<int> orderedNo_;
    for (int i=0; i<orderedNo.size(); i++) {
        if (lowestCost[0][orderedDst[i]] != INF) {
            orderedTime_.push_back(orderedTime[i]);
            orderedDst_.push_back(orderedDst[i]);
            orderedNo_.push_back(orderedNo[i]);
        }
    }
    orderedTime = move(orderedTime_);
    orderedDst = move(orderedDst_);
    orderedNo = move(orderedNo_);
}

void setCmd(vector<int>& cmd, int idx, int val) {
    if (idx < Tmax)
        cmd[idx] = val;
}
int waitUntil(int startTime, int endTime, vector<int>& cmd) {
    for (int i=startTime; i<endTime; i++) {
        setCmd(cmd, i, -1);
    }
    return endTime;
}

int updateOrders(int beforeTime, int nowTime, vector<int>& ords) {
    auto begin = orderedTime.begin();
    auto end = orderedTime.end();
    int ord0 = upper_bound(begin, end, beforeTime) - begin;
    int ord1 = upper_bound(begin, end, nowTime) - begin;
    for (int i=ord0; i<ord1; i++) ords.push_back(i);
    return ord1;
}

int deliver(int startTime, vector<int>& orders, vector<int>& cmd, long long& score) {
    calcPath(startTime, orders);
    int v = 0;
    int time = startTime;
    for (auto o : orders) {
        int dst = orderedDst[o];
        while (v != dst) {
            for (int i=0; i<cost[v][nextV[v][dst]]; i++) {
                assert(nextV[v][dst] != -1);
                assert(cost[v][nextV[v][dst]] != INF);
                setCmd(cmd, time, nextV[v][dst]);
                time++;
            }
            v = nextV[v][dst];
        }
        long long waiting = time - orderedTime[o];
        score += max(0LL, Tmax*Tmax - waiting*waiting);
    }
    int dst = 0;
    while (v != dst) {
        for (int i=0; i<cost[v][nextV[v][dst]]; i++) {
            assert(nextV[v][dst] != -1);
            assert(cost[v][nextV[v][dst]] != INF);
            setCmd(cmd, time, nextV[v][dst]);
            time++;
        }
        v = nextV[v][dst];
    }
    orders.clear();
    return time;
}

int main() {
    input();
    makeCostMap();
    filterOrders();
    long long maxScore = -1;
    vector<int> bestCommand;
    for (int i=0; i<min(WAIT_SIZE, (int)orderedNo.size()); i++) {
        cerr << "iteration " << i << endl;
        long long score = 0;
        vector<int> command(Tmax);
        int curTime = 0;
        int nextTime = waitUntil(curTime, orderedTime[i], command);
        vector<int> orders;
        int nextOrder = updateOrders(-1, nextTime, orders);
        curTime = nextTime;

        while (1) {
            //cerr << "t:" << curTime << " order:" << nextOrder << "/" << orderedNo.size() << endl;
            int nextTime = deliver(curTime, orders, command, score);
            if (nextTime >= Tmax) break;
            if (nextOrder == orderedNo.size()) {
                waitUntil(nextTime, Tmax, command);
                break;
            }
            nextOrder = updateOrders(curTime, nextTime, orders);
            curTime = nextTime;
            if (orders.empty()) {
                if (nextOrder == orderedNo.size())
                    nextTime = waitUntil(curTime, Tmax, command);
                else
                    nextTime = waitUntil(curTime, orderedTime[nextOrder], command);
                nextOrder = updateOrders(curTime, nextTime, orders);
                curTime = nextTime;
                if (curTime >= Tmax) break;
            }
        }
        if (score > maxScore) {
            maxScore = score;
            //cerr << "score: " << score << endl;
            bestCommand = move(command);
        }
    }
    //cerr << "command ready: " << bestCommand.size() << endl;
    for (auto c : bestCommand) {
        if (c == -1) cout << -1 << endl;
        else cout << c+1 << endl;
    }
    return 0;
}



Measured memory_bytes: 2432