#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const ll CYCLE_PER_SEC = 2700000000;
const double TIME_LIMIT = 0.2;
ll startCycle;

unsigned long long xor128() {
    static unsigned long long rx = 123456789, ry = 362436069, rz = 521288629, rw = 88675123;
    unsigned long long rt = (rx ^ (rx << 11));
    rx = ry;
    ry = rz;
    rz = rw;
    return (rw = (rw ^ (rw >> 19)) ^ (rt ^ (rt >> 8)));
}

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);
}

double getTime(unsigned long long int begin_cycle) {
    return (double) (getCycle() - begin_cycle) / CYCLE_PER_SEC;
}

const int MAX_V = 401;
const int MAX_T = 10000;
const ll BASE_SCORE = pow(MAX_T, 2);
const int INF = 99999;

const int UNKNOWN = -1;
const int STORE_ID = 0;

const int WAIT_COMMAND = -1;

int V, E, T, orderCount;
int cost[MAX_V][MAX_V];
ll penalty[MAX_T + 10];

void warshall_floyd(int v = MAX_V) {
    for (int k = 0; k < v; k++) {
        for (int i = 0; i < v; i++) {
            for (int j = 0; j < v; j++) {
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }
}

struct Edge {
    int from;
    int to;
    int dist;

    Edge(int from = -1, int to = -1, int dist = INF) {
        this->from = from;
        this->to = to;
        this->dist = dist;
    }
};

struct Vertex {
    int id;
    int packageCount;
    vector<int> deliver_times;
    vector <Edge> edges;

    Vertex(int id = -1) {
        this->id = id;
        this->packageCount = 0;
    }
};

struct Order {
    int id;
    int dest;
    bool delivered;

    Order(int id = -1, int dest = UNKNOWN) {
        this->id = id;
        this->dest = dest;
        this->delivered = false;
    }
};

struct PathInfo {
    int dist;
    vector<int> path;
};

struct Action {
    int dest;
    int waitCount;

    Action(int dest = -1, int waitCount = 0) {
        this->dest = dest;
        this->waitCount = waitCount;
    }
};

struct Node {
    int v;
    int dist;
    vector<int> path;

    Node(int v = -1, int dist = -1) {
        this->v = v;
        this->dist = dist;
    }

    bool operator>(const Node &n) const {
        return dist > n.dist;
    }
};

vector <Vertex> vertexList;
vector <Edge> edgeList;
Order orderTimeLine[MAX_T + 10];
vector <Order> orderList;
int nextOrderTime[MAX_T + 10];
int deliveredCount[MAX_T + 10];

class HokudaiHitachi {
public:
    void init() {
        for (int i = 0; i < MAX_V; ++i) {
            for (int j = 0; j < MAX_V; ++j) {
                if (i == j) {
                    cost[i][j] = 0;
                } else {
                    cost[i][j] = INF;
                }
            }
        }

        for (int t = MAX_T; t >= 0; --t) {
            nextOrderTime[t] = MAX_T;
            penalty[t] = pow(t, 2);
        }
    }

    vector <Action> initSolver() {
        vector <Action> result;

        if (orderTimeLine[0].dest != UNKNOWN) {
            result.push_back(Action(STORE_ID, 0));
        } else {
            result.push_back(Action(STORE_ID, 10));
        }

        for (int i = 0; i < orderCount; ++i) {
            Order *order = &orderList[i];
            assert(order->dest != UNKNOWN);
            result.push_back(Action(order->dest));

            if ((i + 1) % 20 == 0) {
                result.push_back(Action(STORE_ID, 0));
            }
        }

        return result;
    }

    vector<int> run() {
        int time = 0;
        int before = 0;
        vector<int> path;
        setupDeliveredCount(0);

        while (time < T) {
            vector<int> packList = getPackageList(before, time);
            before = time + 1;

            if (packList.empty()) {
                time = nextOrderTime[time];

                for (int i = 0; i < time - before; ++i) {
                    path.push_back(WAIT_COMMAND);
                }
            } else {
                vector<int> result = buildDeliveryPath(packList, time, before - 1);
                int current = STORE_ID;
                bool flg = true;

                for (int i = 0; i < result.size() && flg; ++i) {
                    int to = result[i];
                    PathInfo pathinfo = getPath(current, to);

                    for (int j = 0; j < pathinfo.path.size(); ++j) {
                        int dst = pathinfo.path[j];
                        vector<int> stockOrder = getPackageList(before, time);
                        int stockSize = stockOrder.size() - packList.size();
                        double rate = stockSize / (max(1, cost[current][STORE_ID]));

                        if ((stockSize > 0 && rate >= 1.0) || dst == STORE_ID) {
                            flg = false;
                            break;
                        }

                        time += cost[current][dst];

                        path.push_back(dst);
                        current = dst;

                        // delivered order
                        int cnt = deliveredCount[current];
                        Vertex *vertex = &vertexList[current];

                        while (cnt < vertex->packageCount && vertex->deliver_times[cnt] <= before - 1) {
                            orderTimeLine[vertex->deliver_times[cnt]].delivered = true;
                            ++cnt;
                        }

                        deliveredCount[current] = cnt;
                    }
                }

                time += cost[current][STORE_ID];
                path.push_back(STORE_ID);
            }

            fprintf(stderr, "time = %d\n", time);
        }

        setupDeliveredCount(0);
        ll score = calcScore(path, 0, true);

        fprintf(stderr, "Score = %lld\n", score);

        return path2answer(path);
    }

    vector<int> getPackageList(int from, int to) {
        vector<int> result;
        bool checked[V];
        memset(checked, false, sizeof(checked));

        if (to >= T) return result;

        for (int t = 0; t <= to; ++t) {
            int dest = orderTimeLine[t].dest;

            if (dest == UNKNOWN) continue;
            if (orderTimeLine[t].delivered) continue;
            if (checked[dest]) continue;
            checked[dest] = true;

            result.push_back(dest);
        }

        return result;
    }

    void setupDeliveredCount(int time) {
        assert(time <= T);
        memset(deliveredCount, 0, sizeof(deliveredCount));

        for (int t = 0; t <= time; ++t) {
            int dest = orderTimeLine[t].dest;
            if (dest == UNKNOWN) continue;

            ++deliveredCount[dest];
        }
    }

    vector<int> buildDeliveryPath(vector<int> &packageList, int started_at, int last_at) {
        if (packageList.size() <= 2) return packageList;

        // setupDeliveredCount(last_at);
        vector<int> bestPath = packageList;
        vector<int> path = bestPath;
        ll bestScore = calcScore(bestPath, started_at);
        ll currentScore = bestScore;
        startCycle = getCycle();

        fprintf(stderr, "%5d: buildDeliveryPath (%d) - FirstScore = %lld\n", started_at, (int) packageList.size(),
                bestScore);

        double currentTime = getTime(startCycle);
        int tryCount = 0;
        int len = path.size();

        int R = 500000;
        double k = 1.0;
        double diffScore;

        while (currentTime < TIME_LIMIT) {
            currentTime = getTime(startCycle);
            double remainTime = (TIME_LIMIT - currentTime) / TIME_LIMIT;

            int type = xor128() % 3;

            int i, j, a, b, temp;

            do {
                i = xor128() % len;
                j = xor128() % len;
            } while (i == j);

            switch (type) {
                case 0:
                    swap(path[i], path[j]);
                    break;
                case 1:
                    temp = path[i];
                    path.erase(path.begin() + i);
                    path.insert(path.begin() + j, temp);
                    break;
                case 2:
                    if (i > j) {
                        temp = i;
                        i = j;
                        j = temp;
                    }

                    a = i;
                    b = j;

                    while (i < j) {
                        swap(path[i], path[j]);

                        ++i;
                        --j;
                    }
                    break;
            }

            ll score = calcScore(path, started_at);
            diffScore = 100 * (score - currentScore) / (double) BASE_SCORE;

            if (currentScore < score || (xor128() % R < R * exp(diffScore / (k * sqrt(remainTime))))) {
                currentScore = score;

                if (bestScore < score) {
                    bestScore = score;
                    bestPath = path;
                }
            } else {
                switch (type) {
                    case 0:
                        swap(path[i], path[j]);
                        break;
                    case 1:
                        path = bestPath;
                        break;
                    case 2:
                        path = bestPath;
                        break;
                }
            }

            ++tryCount;
        }

        fprintf(stderr, "bestScore = %lld, tryCount = %d\n", bestScore, tryCount);

        return bestPath;
    }

    vector<int> path2answer(vector<int> &path) {
        int current = STORE_ID;
        int time = 0;
        vector<int> answer;

        for (int i = 0; i < path.size() && time < MAX_T; ++i) {
            int dest = path[i];
            if (dest == WAIT_COMMAND) {
                answer.push_back(WAIT_COMMAND);
                continue;
            }

            PathInfo pathInfo = getPath(current, dest);

            for (int j = 0; j < pathInfo.path.size(); ++j) {
                int to = pathInfo.path[j];
                int d = cost[current][to];

                assert(STORE_ID <= to && to <= V - 1);
                assert(d > 0);

                while (time < MAX_T && d > 0) {
                    answer.push_back(to + 1);
                    ++time;
                    --d;
                }

                current = to;
            }
        }

        while (answer.size() < MAX_T) {
            answer.push_back(WAIT_COMMAND);
        }

        return answer;
    }

    ll calcScore(vector<int> &path, int started_at, bool real = false) {
        ll totalScore = 0;

        int time = started_at;
        int current = STORE_ID;

        for (int i = 0; i < path.size() && time < T; ++i) {
            Vertex *vertex = &vertexList[current];
            int dest = path[i];

            if (current == STORE_ID) {
                started_at = time;
            }

            if (dest == WAIT_COMMAND) {
                assert(current == STORE_ID);
                ++time;
                continue;
            }

            if (dest < 0 || V <= dest) {
                fprintf(stderr, "dest = %d\n", dest);
            }
            assert(STORE_ID <= current && current < V);
            assert(STORE_ID <= dest && dest < V);

            if (current != dest) {
                if (cost[current][dest] > MAX_T) {
                    fprintf(stderr, "%d -> %d cost %d\n", current, dest, cost[current][dest]);
                }

                assert(cost[current][dest] <= MAX_T);
                time += cost[current][dest];
                current = dest;
            }

            if (time > MAX_T) {
                // fprintf(stderr, "Time over: %d\n", time);
                break;
            }
            assert(time <= MAX_T);

            // delivered order
            int cnt = deliveredCount[current];

            while (cnt < vertex->packageCount && vertex->deliver_times[cnt] <= started_at) {
                int delay = time - vertex->deliver_times[cnt];
                assert(0 <= delay && delay <= MAX_T);
                totalScore += BASE_SCORE - penalty[delay];
                ++cnt;
            }

            if (real) {
                deliveredCount[current] = cnt;
            }
        }

        time += cost[current][STORE_ID];

        return totalScore - pow(time - started_at, 2);
    }

    PathInfo getPath(int from, int to) {
        PathInfo pathInfo;
        pathInfo.dist = 0;

        priority_queue <Node, vector<Node>, greater<Node>> pque;
        pque.push(Node(from, 0));

        bool visited[V];
        memset(visited, false, sizeof(visited));

        while (!pque.empty()) {
            Node node = pque.top();
            pque.pop();

            if (visited[node.v]) continue;
            visited[node.v] = true;

            if (node.v == to) {
                pathInfo.path = node.path;
                pathInfo.dist = node.dist;
                break;
            }

            for (int i = 0; i < vertexList[node.v].edges.size(); ++i) {
                Edge *edge = &vertexList[node.v].edges[i];

                assert(edge->from == node.v);

                Node next(edge->to, node.dist + edge->dist);
                next.path = node.path;
                next.path.push_back(edge->to);

                pque.push(next);
            }
        }

        return pathInfo;
    }
};

int main() {
    HokudaiHitachi hh;
    hh.init();
    cin >> V >> E;

    for (int vid = 0; vid < V; ++vid) {
        Vertex vertex(vid);

        vertexList.push_back(vertex);
    }

    int u, v, d;
    for (int i = 0; i < E; ++i) {
        cin >> u >> v >> d;

        --u;
        --v;

        cost[u][v] = d;
        cost[v][u] = d;

        Edge e1(u, v, d);
        Edge e2(v, u, d);

        edgeList.push_back(e1);

        vertexList[u].edges.push_back(e1);
        vertexList[v].edges.push_back(e2);
    }

    warshall_floyd(V);

    cin >> T;

    int N;
    int id, dst;
    orderCount = 0;

    for (int t = 0; t < T; ++t) {
        cin >> N;
        if (N == 0) continue;

        cin >> id >> dst;
        --dst;
        Order order(id, dst);
        orderTimeLine[t] = order;
        orderList.push_back(order);
        vertexList[dst].deliver_times.push_back(t);
        ++vertexList[dst].packageCount;
        ++orderCount;
    }

    fprintf(stderr, "Order Count = %d\n", orderCount);

    int nextTime = T;

    for (int t = T; t >= 0; --t) {
        nextOrderTime[t] = nextTime;

        if (orderTimeLine[t].dest != UNKNOWN) {
            nextTime = t + 1;
        }
    }

    vector<int> result = hh.run();

    for (int t = 0; t < T; ++t) {
        cout << result[t] << endl;
    }

    return 0;
}

Measured memory_bytes: 1536