#include "bits/stdc++.h"

using namespace std;

using ll = long long;
constexpr ll TMAX = 10000, MAX_N = 400, TIME_LIMIT = 20000;
constexpr int inf = 1e9;
constexpr int DEPARTURE = 5000;
vector<int> destinations;

struct XorShift {
  using result_type = uint32_t;
  result_type w = 123456789, x = 362436069, y = 521288629, z = 88675123;
  XorShift(result_type seed = time(nullptr)) {
    w = seed;
    x = w << 13;
    y = (w >> 9) ^ (x << 6);
    z = y >> 7;
  }
  static const result_type min() { return 0; }
  static const result_type max() { return 0x7FFFFFFF; }
  result_type operator()() {
    result_type t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19) ^ (t ^ (t >> 8)));
  }
  result_type rand() {
    result_type t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19) ^ (t ^ (t >> 8)));
  }
  // [min,max] の整数値乱数
  result_type randInt(result_type min = 0, result_type max = 0x7FFFFFFF) {
    return rand() % (max - min + 1) + min;
  }
};

XorShift rnd(114514);

struct Edge
{
    int to, cost; // cost <= 4 sqrt(2V)
    Edge(int t, int c) : to(t), cost(c) {}
};

struct Position{
    int from, to, remain;
    bool isStart = true;
    Position(int f, int t, int r) : from(f), to(t), remain(r) {}
    Position() : from(0), to(0), remain(0) {}
};

struct Order{
    int orderTime, id, dst;
    Order(int o, int i, int d) : orderTime(o), id(i), dst(d) {}
};

struct Profit{
    ll cnt, order_sum, order_sq_sum;
    Profit() : cnt(0), order_sum(0), order_sq_sum(0){}
};

ll calcProfit(ll deliverTime, const Profit &p){
    ll ret = -p.cnt * deliverTime * deliverTime + (p.cnt * TMAX * TMAX - p.order_sq_sum) + 2 * p.order_sum * deliverTime;
    return ret;
}

using Graph = vector<vector<Edge>>;
Graph g;

int V, E; // 200<=V<=400, 1.5V<=E<=2V
vector<vector<int>> dist(MAX_N, vector<int>(MAX_N, inf));
// orders that is pending at vertex 1
vector<Order> orders;
// profits[i] := profit if the car reaches vertex i
vector<Profit> profits(MAX_N);
vector<int> freq(MAX_N);

Position pos;

void input_gomi()
{
    for(int i=0;i<V;i++) cin >> freq[i];
    int gomi;
    cin >> gomi;
}

void input_gomi2(){
    int n_put;cin>>n_put;
    for(int i=0;i<n_put;i++){
        int id;
        cin>>id;
    }
}

void input_verdict(){
    string s;cin>>s;
    assert(s=="OK");
    int n_arc;cin>>n_arc;
    for(int i=0;i<n_arc;i++){
        int id;cin>>id;
    }
}

// (next vertex, next dist)
Edge nxtHop(int dst){
    for(const auto &e:g[pos.to]){
        if(dist[pos.to][dst] == dist[pos.to][e.to] + dist[e.to][dst]){
            return e;
        }
    }
    assert(false);
}

void input_order(int turn){
    cerr << "input start" << endl;
    int n_new;cin>>n_new;
    //cerr << "new is " << n_new << endl;
    for(int i=0;i<n_new;i++){
        int id, dst;cin>>id>>dst;
        dst--;
        //cerr << pos.from << " " << pos.to << endl;
        orders.push_back(Order(turn, id, dst));
    }
    if(pos.isStart){
        for(const auto &order:orders){
            int dst = order.dst;
            profits[dst].cnt++;
            profits[dst].order_sum += order.orderTime;
            profits[dst].order_sq_sum += order.orderTime * order.orderTime;
            //cerr << profits[dst].cnt << " " << profits[dst].order_sum << " " << profits[dst].order_sq_sum << endl;
        }
        orders.clear();
    }
    input_gomi2();
}

void stay(){
    cout << -1 << endl;
}

ll profit_sum = 0;

void moving(int turn){
    //cerr << "move to " << pos.to << endl;
    cout << pos.to + 1 << endl;
    pos.remain--;
    pos.isStart = false;
    if(pos.remain) return;
    profit_sum += calcProfit(turn+1, profits[pos.to]);
    profits[pos.to] = Profit();
    assert(destinations.size());
    int dst = destinations[0];
    auto e = nxtHop(dst);
    pos.from = pos.to;
    pos.to = e.to;
    pos.remain = e.cost;
    if(e.to==destinations[0])destinations.erase(destinations.begin());
    if(pos.from == 0) pos.isStart = true;
    cerr << "next vertex is " << pos.to << endl;
}

int main(){
    cin >> V >> E;
    g.resize(V);
    for(int i=0;i<V;i++) dist[i][i] = 0;
    for(int i=0;i<E;i++) {
        int u,v,d;cin>>u>>v>>d;
        u--;v--;
        g[u].push_back(Edge(v, d));
        g[v].push_back(Edge(u, d));
        dist[u][v] = dist[v][u] = d;
    }
    input_gomi();
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    for(int turn=0;turn<TMAX;turn++){
        cerr << "turn " << turn << " start" << endl;
        input_order(turn);
        if(turn<DEPARTURE){
            cerr << "stay" << endl;
            stay();
            input_verdict();
            continue;
        }
        else if(turn>DEPARTURE){
            cerr << "moving" << endl;
            moving(turn);
            input_verdict();
            continue;
        }
        cerr << "calc route" << endl;
        for(int i=0;i<V;i++){
            if(profits[i].cnt==0) continue;
            destinations.push_back(i);
        }
        shuffle(destinations.begin(),destinations.end(), rnd);
        {
            assert(destinations.size());
            int dst = destinations[0];
            auto e = nxtHop(dst);
            pos.from = pos.to;
            pos.to = e.to;
            pos.remain = e.cost;
            if(e.to==destinations[0])destinations.erase(destinations.begin());
        }
        moving(turn);
        input_verdict();
    }
    cerr << profit_sum << endl;
}


Measured memory_bytes: 2128