#define ONLINE

#include<bits/stdc++.h>

using namespace std;

struct Order{
    int id, dst;
    Order(int _i=0, int _d=0): id(_i), dst(_d) {}
};

struct Command{
    int v;
    Command(int _v=-1): v(_v) {}

    void show(void){
        if(v != -1) printf("%d\n", v+1);
        else printf("-1\n");
        fflush(stdout);
    }
};

const int MAXV = 400 + 10;
const int MAXE = 2 * MAXV;
const int MAXT = 10000 + 10;
const int INF = 1000000000;

/* ======================================== */

vector<vector<int>> get_graph(void){
    vector<vector<int>> edges;
    int nv, ne;
    scanf("%d%d", &nv, &ne);
    edges.assign(nv, vector<int>(nv, INF));
    for(int i=0; i<ne; ++i){
        int u, v, d;
        scanf("%d%d%d", &u, &v, &d); --u, --v;
        edges[u][v] = edges[v][u] = d;
    }
    return edges;
}

vector<int> get_frequency(int n){
    vector<int> fs(n);
    for(int i=0; i<n; ++i)
        scanf("%d", &fs[i]);
    return fs;
}

int get_tmax(void){
    int tmax;
    scanf("%d", &tmax);
    return tmax;
}

Order get_order(void){
    int has_order;
    Order order;
    scanf("%d", &has_order);
    if(has_order){
        scanf("%d%d", &order.id, &order.dst);
        --order.dst;
    }
#ifdef ONLINE
    int n_put;
    scanf("%d", &n_put);
    for(int i=0; i<n_put; ++i){
        int id;
        scanf("%d", &id);
    }
#endif // ONLINE
    return order;
}

vector<Order> get_orders(int n){
    vector<Order> orders(n);
    for(int i=0; i<n; ++i)
        orders[i] = get_order();
    return orders;
}

bool show_command(int n, vector<Command> cmds){
    char temp[10];
    for(int i=0; i<n; ++i){
        cmds[i].show();
#ifdef ONLINE
        scanf("%s", temp);
        if(temp[0] == 'N') return false;
        int n_achieve;
        scanf("%d", &n_achieve);
        for(int j=0; j<n_achieve; ++j){
            int t;
            scanf("%d", &t);
        }
#endif // ONLINE
    }
    return true;
}

/* ======================================== */

int tmax;
int nv;
vector<vector<int>> edges;
vector<int> fs;
vector<Order> orders;

vector<vector<int>> dists;
vector<vector<int>> dirs;

void apsp(void){
    dists = edges;
    for(int k=0; k<nv; ++k)
        for(int i=0; i<nv; ++i)
            for(int j=0; j<nv; ++j)
                dists[i][j] = min(dists[i][j], dists[i][k]+dists[k][j]);
    for(int i=0; i<nv; ++i) dists[i][i] = 0;
}

void solve_offline(void){
    edges = get_graph();
    tmax = get_tmax();
    orders = get_orders(tmax);
    for(int i=0; i<tmax; ++i) Command().show();
}

void solve_online(void){
    edges = get_graph();
    nv = edges.size();
    fs = get_frequency(nv);
    tmax = get_tmax();

    apsp();
    dirs.assign(nv, vector<int>(nv, -1));
    for(int i=0; i<nv; ++i)
        for(int j=0; j<nv; ++j)
            if(i == j) dirs[i][j] = i;
            else
                for(int d=0; d<nv; ++d){
                    if(dists[i][j] == edges[i][d] + dists[d][j]){
                        dirs[i][j] = d;
                        assert(edges[i][d] != INF);
                        break;
                    }
                }

    tuple<int, int, int> pos{0, 0, 0};

    int i_pick = 0, i_dlvr = 0;
    vector<int> dsts(tmax), pick(tmax), dlvr(tmax);
    vector<queue<int>> times(nv);

    for(int t=0; t<tmax; ++t){
        Order order = get_order();

        // add order to pick up queue
        if(order.id){
            dsts[t] = order.dst;
            times[order.dst].push(t);
        }

        // pick up order if at shop
        if(get<0>(pos)==0 && get<2>(pos)==0){
            for(; i_pick<=t; ++i_pick){
                if(dsts[i_pick]) pick[i_pick] = 1;
            }
        }

        // move / stay
        Command cmd;
        int cur = get<0>(pos), dst = dsts[i_dlvr];
        if(!pick[i_dlvr]) dst = 0;
        int dir = dirs[cur][dst];
        if(cur != dir){
            cmd.v = dir;
            get<1>(pos) = dir;
            ++get<2>(pos);
        }
        if(get<2>(pos) == edges[cur][dir]){
            pos = make_tuple(dir, dir, 0);
        }
        show_command(1, vector<Command>{cmd});

        // deliver
        if(get<2>(pos) == 0){
            int v = get<0>(pos);
            while(!times[v].empty() && times[v].front()<i_pick){
                dlvr[times[v].front()] = 1;
                times[v].pop();
            }
        }
        while(i_dlvr <= t){
            if(dsts[i_dlvr]==0 || dlvr[i_dlvr]==1)
                ++i_dlvr;
            else
                break;
        }
    }
}

int main(){
/*
#ifdef ONLINE
    freopen("in_online", "r", stdin);
#else
    freopen("in", "r", stdin);
#endif // ONLINE
// */

#ifdef ONLINE
    solve_online();
#else
    solve_offline();
#endif // ONLINE
    return 0;
}

/*
toolkitA\scripts\generator.exe in 1 1
a < in > out
toolkitA\scripts\output_checker.exe in out
*/
/*
python toolkitB\scripts\interactive.py --judge "./toolkitB/scripts/judge.exe 1 1" --contestant a.exe > log
*/


Measured memory_bytes: 3788