#define NOMINMAX
#define TEST_MODE false

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <random>
#include <regex>
#include <unordered_set>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " : " << (x) << " "
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x)
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x)
#define dumpl(x)
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int inf = (int)1 << 60;
const int undefined = inf;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
typedef long double Real;
const Real eps = 1e-10;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
//const int MAX = (int)2e5 + 5;
const int MAX = 405;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <typename T>
string join(const vector<T> &v, const string delim = 0, function<string(T)> f = [](int a) { return to_string(a); })
{
    string s;
    if (!v.empty())
    {
        s += f(v[0]);
        for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i)
        {
            if (delim != "")
                s += delim;
            s += f(v[i]);
        }
    }
    return s;
}

string join_str(const vector<string> &v, const string delim = 0)
{
    return join<string>(v, delim, [](string a) { return a; });
}

string operator*(const string &s, const int &n)
{
    string res = "";
    rep(i, n) res += s;
    return res;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

template <typename T>
T gcd(T a, T b)
{
    if (a == inf)
        return b;
    if (b == inf)
        return a;
    T c;
    while (a != 0)
    {
        c = a;
        a = b % a;
        b = c;
    }
    return b;
}

template <typename T>
T lcm(T m, T n)
{
    return ((m / gcd(m, n)) * n);
}

template <typename T>
T bit_count(T N)
{
    T cnt = 0;
    while (N)
    {
        if (N & 1)
            cnt++;
        N >>= 1;
    }
    return cnt;
}

template <typename T>
void print_vec(ostream &ostream, vector<T> a)
{
#ifndef LOCAL_ENV
    return;
#endif
    rep(i, a.size() - 1) ostream << a[i] << " ";
    ostream << a.back() << endl;
}

ll pow_n(ll x, ll n)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x;
        x = x * x;
        n >>= 1;
    }
    return res;
}

template <class T, class U>
T mod_pow(T x, U n)
{
    T res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x;
        x = x * x;
        x %= mod_n;
        n >>= 1;
        res %= mod_n;
    }
    return res;
}

template <class T>
T mod_rev(T a)
{
    T res = 1;
    return mod_pow(a, mod_n - 2);
}

int H, W;

bool grid_ng(int y, int x)
{
    return y < 0 || y >= H || x < 0 || x >= W;
}

struct Point
{
    int x, y;
    Point(int y_, int x_) : y(y_), x(x_) {}
    bool operator<(const Point &r) const
    {
        if (y != r.y)
            return y < r.y;
        return x < r.x;
    }
};

struct Vertex
{
    int id, dist;
    bool operator>(const Vertex &r) const
    {
        return dist > r.dist;
    }
};

struct Edge
{
    int to, weight;
    Edge(int to, int weight) : to(to), weight(weight) {}
};

// using Graph = vector<unordered_map<int, int>>;
using Graph = vector<vector<Edge>>;
Graph g;

map<pair<int, int>, int> pair_to_weight;

struct OrderAtTime
{
    int n, id, dst;
};

vector<OrderAtTime> orders;

void read_info(int i)
{
    OrderAtTime &o = orders[i];
    cin >> o.n;
    if (o.n == 1)
    {
        cin >> o.id >> o.dst;
        dump(o.n);
        dump(o.id);
        dumpl(o.dst);
    }
}

void input()
{
    int v_size, e_size;
    cin >> v_size >> e_size;

    g.resize(v_size + 1);
    rep(i, e_size)
    {
        int u, v, d;
        cin >> u >> v >> d;
        g[u].push_back(Edge(v, d));
        g[v].push_back(Edge(u, d));
        pair_to_weight[make_pair(u, v)] = d;
        pair_to_weight[make_pair(v, u)] = d;
    }
    int t_max;
    cin >> t_max;
    dumpl(t_max);

    orders.resize(t_max);
    rep(i, t_max)
    {
        read_info(i);
    }
}

vector<vector<int>> pre_vertex;
int goal_id;

void dijkstra(int start_id, vector<int> &d)
{
    rep(i, g.size() + 1)
    {
        // d[i]= INFL;
        d.at(i) = INFL;
    }
    // d[start_id] = 0;
    d.at(start_id) = 0;
    priority_queue<Vertex, vector<Vertex>, greater<Vertex>> q;
    Vertex start;
    start.id = start_id;
    start.dist = 0;
    for (q.push(start); !q.empty();)
    {
        Vertex p = q.top();
        q.pop();
        // if (pre_vertex[start_id][p.dist] != -1) continue;
        for (auto f : g[p.id])
        {
            Vertex next_p;
            next_p.id = f.to;
            next_p.dist = p.dist + f.weight;
            if (d[next_p.id] > next_p.dist)
            {
                if (pre_vertex.at(start_id).at(f.to) != -1)
                    continue;
                pre_vertex.at(start_id).at(f.to) = p.id;
                d[next_p.id] = next_p.dist;
                q.push(next_p);
            }
        }
    }
}

vector<int> build_path(const vector<vector<int>> &prev, int start, int t)
{
    vector<int> path;
    for (int u = t; u >= 0; u = prev[start][u])
        path.push_back(u);
    reverse(path.begin(), path.end());
    return path;
}

void output()
{
    pre_vertex.resize(g.size() + 1);
    rep(i, g.size())
    {
        pre_vertex[i].resize(g.size() + 1);
        rep(j, g.size()) pre_vertex[i][j] = -1;
    }
    vector<vector<int>> d(g.size() + 1);
    rep(i, g.size() + 1) d[i].resize(g.size() + 1);

    rep2(i, 1, g.size()) dijkstra(i, d[i]);
    //cout << "!" << endl;
    rep2(i, 1, g.size()) rep2(j, 1, g.size())
    {
        auto vec = build_path(pre_vertex, i, j);
        dump(i);
        dump(j);
#ifdef LOCAL_ENV
        cerr << ": ";
#endif
        print_vec(cerr, vec);
    }

    // auto next_customer_itr = orders.begin();

    int next_customer = 0;
    auto path = vector<int>();
    //auto path_itr = path.begin();

    int path_id;
    bool is_store_next = false;
    int rest;
    int cur_vertex = 1;

    dumpl(orders.size());
    rep(i, orders.size())
    {
        //dumpl(next_customer_itr->n);
        //while (next_customer_itr->n == 0) {
        while (next_customer < orders.size() && orders.at(next_customer).n == 0)
        {
            //if (next_customer_itr == orders.end()) {
            //	break;
            //}
            next_customer++;
        }

        int res;
        //dumpl(next_customer_itr->n);
        //ifnot (next_customer_itr != orders.end()) {
        if (next_customer >= orders.size() || next_customer > i)
        {
            res = -1;
        }
        else
        {
            if (path.size() == 0)
            {
                //path = build_path(pre_vertex, cur_vertex, next_customer_itr->id);
                if (cur_vertex == 1)
                {
                    path = build_path(pre_vertex, cur_vertex, orders.at(next_customer).dst);
                }
                else
                {
                    path = build_path(pre_vertex, cur_vertex, 1);
                }
                dumpl(cur_vertex);
                dumpl(next_customer);
                dumpl(orders.at(next_customer).dst);
                //cerr << "path: ";  print_vec(cerr, path);
                // path_itr = path.begin();
                path_id = 0;
                // rest = pair_to_weight[make_pair(*path_itr, *(path_itr + 1))];
                //rest = pair_to_weight[make_pair(orders[path_id].dst, orders[path_id + 1].dst)];
                path_id = 1;

                rest = pair_to_weight[make_pair(path[path_id - 1], path[path_id])];
            }
            //res = *path_itr;
            res = path[path_id];
            rest--;
            if (rest == 0)
            {
                path_id++;
                if (path_id < path.size())
                {
                    rest = pair_to_weight[make_pair(path[path_id - 1], path[path_id])];
                }
                else
                {
                    path.clear();
                    cur_vertex = res;
                    if (cur_vertex == 1)
                    {
                        next_customer += 1;
                        cerr << "next_customer: " << next_customer << endl;
                    }
                }
            }
        }
        cout << res << endl;
    }
}

void solve()
{
    input();
    output();
}

signed main()
{
    srand(time(NULL));

    //#ifdef LOCAL_ENV
    //	std::ifstream in("in.txt");
    //	std::cin.rdbuf(in.rdbuf());
    //#endif

    solve();

    return 0;
}

Measured memory_bytes: 3200