#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]



#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

#[allow(unused_macros)]
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

 
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
 
 
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

use std::cmp;
use std::collections::HashMap;
use std::io::{self, Write};

#[allow(dead_code)]
static INF_I64 :i64 = 9223372036854775807;
#[allow(dead_code)]
static INF_I32 : i32 = 2147483647;
#[allow(dead_code)]
static INF_USIZE : usize = 7446744073709551615;

fn post(ret:&str,time:usize)->Vec<(usize,usize,usize)>{
    let mut info = vec![];
    let a = get!(usize);
    println!("{}",ret);
    io::stdout().flush().unwrap();
    if a == 0 {
        //info.push(vec![(0,500)]);
        //continue;
        info.push((10000000,0,0));
        
    }
    else{
        let items = get!(usize,usize;a);
        for j in 0..items.len(){
            let tmp = items[j];
            info.push((time,tmp.0-1,tmp.1-1));
        }
    }
    return info;
}

fn main() {

    let (n,m) = get!(usize,usize);
    mydbg!(n,m);

    let mut edges = get!(usize,usize,usize;m);
    let tmax = get!(usize);
    let mut info:Vec<(usize,usize,usize)> = vec![];
    // for i in 0..tmax{
    //     let a = get!(usize);
    //     if a == 0 {
    //         //info.push(vec![(0,500)]);
    //         continue;
    //     }
    //     let items = get!(usize,usize;a);
    //     for j in 0..items.len(){
    //         let tmp = items[j];
    //         info.push((i,tmp.0,tmp.1));
    //     }
        
    // }
    
 
 
    // for i in 0..info.len(){
    //     let a= info[i];
    //     info[i]  = (a.0,a.1-1,a.2-1);
    // }
    

    let mut dp = vec![vec![INF_USIZE;n];n];

    for i in 0..m{
        let e = edges[i];
        dp[e.0-1][e.1-1] = e.2;
        dp[e.1-1][e.0-1] = e.2;
        dp[e.0-1][e.0-1] = 0;
        dp[e.1-1][e.1-1] = 0;
    }

    let mut next = vec![vec![n;n];n];
    for i in 0..n{
        for j in 0..n{
            next[i][j] = j;
        }
    }

    for k in 0..n{
        for i in 0..n{
            for j in 0..n{
                let tmp = dp[i][k]+dp[k][j];
                if tmp < dp[i][j]{
                    dp[i][j] = tmp;
                    next[i][j] = next[i][k];
                }
            }
        }
    }


    let mut maxcost = 0;
    for i in 0..n{
        maxcost = cmp::max(maxcost, dp[i][0]);
    }
    mydbg!(maxcost);
    //mydbg!(dp);
    
    let mut cur = 0;
    let mut ans:Vec<i32> = vec![];
    let mut time = 0;
    let mut used = vec![0;info.len()];
    mydbg!(used.len(),info.len(),next.len(),dp.len());
    let mut package = vec![];
    let mut present = 0;
    let mut now = 0;
    
    loop{
        if time >= tmax{
            break;
        }
        
        // for i in cur..info.len(){
        //     if info[i].0 <= time{
        //         package.push(info[i]);
        //     }
        //     else {
        //         cur = i;
        //         break;
        //     }
        // }
        for i in 0..info.len(){
            if info[i].0 == 10000000{
                continue;
            }
            else if info[i].0 == 10000001{
                break;
            }
            package.push(info[i]);
        }
        info =vec![];

        if package.len() == 0 {
            time += 1;
            //ans.push(-1);
            now += 1;
            if now > tmax {
                return;
            }
            let tmp = post(&"-1",now);
            for i in 0..tmp.len(){
                info.push(tmp[i]);
            }
            continue;
        }

        //mydbg!(package);
        mydbg!(package.len());
        //package.reverse();

        loop{
            let mut path = vec![];
            //mydbg!(package.len());
            if false {
                package.sort_by(|x,y|{
                    if dp[present][x.2] > dp[present][y.2]{
                        cmp::Ordering::Less
                    }
                    else if dp[present][x.2] == dp[present][y.2]{
                        cmp::Ordering::Equal
                    }
                    else{
                        cmp::Ordering::Greater
                    }
                });
            }
            if true {
                package.sort_by(|x,y|{
                    if dp[present][x.2] > dp[present][y.2]{
                        cmp::Ordering::Less
                    }
                    else if dp[present][x.2] == dp[present][y.2]{
                        return y.0.cmp(&x.0);
                    }
                    else{
                        cmp::Ordering::Greater
                    }
                });
            }
            if false {
                package.sort_by(|x,y|{
                    let dtx = dp[present][x.2];
                    let dty = dp[present][y.2];
                    let wtx = now+dtx - x.0;
                    let wty = now+dty - y.0;
                    if wtx > wty{
                        cmp::Ordering::Less
                    }
                    else if wtx == wty{
                        cmp::Ordering::Equal
                    }
                    else{
                        cmp::Ordering::Greater
                    }
                });
            }
           
           

            let tmp = package[package.len()-1];
            //mydbg!(tmp);
            let g = tmp.2;
            let mut target = present;
            //let g = 0;
            //let mut target = tmp.2;
            loop{
                target = next[target][g];
                path.push(target);
                if target == g{
                    break;
                }
            }

            //let mut b = present;
            'outer : for i in 0..path.len(){
                //mydbg!(b,*item,dp[b][*item]);
                let item = path[i];
                for _ in 0..dp[present][item]{
                    //ans.push(item as i32+1);
                    now += 1;
                    if now > tmax {
                        return;
                    }
                    let tmp = post(&(item as i32+1).to_string(),now);
                    for i in 0..tmp.len(){
                        info.push(tmp[i]);
                    }
                }
                present = item;
                //if i != path.len()-1 &&  dp[present][0] < dp[present][path[i+1]]{
                if i != path.len()-1{
                    //if dp[present][0]*2 < dp[present][path[i+1]] {
                    if false {
                        mydbg!("戻る");
                        loop{
                            let t = next[present][0];
                            for _ in 0..dp[present][t]{
                                //ans.push(t as i32+1);
                                now += 1;
                                if now > tmax {
                                    return;
                                }
                                let tmp = post(&(t as i32+1).to_string(),now);
                                for i in 0..tmp.len(){
                                    info.push(tmp[i]);
                                }
                            }
                            present = t;
                            if present == 0{
                                break;
                            }
                        }
                        break 'outer;
                    }
                }
            }

            package.pop();
            //mydbg!(package.len());
            if false && present == 0 {
                break;
            }
            if package.len() == 0 {
            //if true { //一回配達するごとに絶対もどる
                //mydbg!("戻る2");
                loop{
                    let t = next[present][0];
                    for _ in 0..dp[present][t]{
                        //ans.push(t as i32+1);
                        now += 1;
                        if now > tmax {
                            return;
                        }
                        let tmp = post(&(t as i32+1).to_string(),now);
                        for i in 0..tmp.len(){
                            info.push(tmp[i]);
                        }
                    }
                    present = t;
                    if present == 0{
                        break;
                    }
                }
                break;
            }

            //if dp[present][0] < maxcost / 10  && dp[present][0]*2 < dp[present][package[package.len()-1].2]{
            if dp[present][0] < 10 && info.len() > 10 { //462982464483 good
            //if dp[present][0] < maxcost / 7 && info.len() > 13 { //462982464483 good
            //if dp[present][0] < 30 { //47137482026
            //if dp[present][0] < 60 { // 47333223951
            //if dp[present][0] < 50 { // 47137482026
            //if dp[present][0] < 70 { // 47333223951
            //if dp[present][0] < 90 { // 47333223951
            //if false {
                mydbg!("戻る3");
                loop{
                    let t = next[present][0];
                    for _ in 0..dp[present][t]{
                        //ans.push(t as i32+1);
                        now += 1;
                        if now > tmax {
                            return;
                        }
                        let tmp = post(&(t as i32+1).to_string(),now);
                        for i in 0..tmp.len(){
                            info.push(tmp[i]);
                        }
                    }
                    present = t;
                    if present == 0{
                        break;
                    }
                }
                time = ans.len();
                break;
            }
            
            
            time = ans.len();
        }

        time = ans.len();

    }

 
 



}



Measured memory_bytes: 6524