#![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;


#[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 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![];
    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..n{
    //    let e= edges[i];
    //    edges[i] = (e.0-1,e.1-1,e.2);
    //}

    for i in 0..info.len(){
        let a= info[i];
        info[i]  = (a.0,a.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];
                }
            }
        }
    }

    //mydbg!(dp);
    
    let mut cur = 0;
    let mut ans:Vec<i32> = vec![];
    let mut time = 0;
    loop{

        let mut package = vec![];
        for i in cur..{
            if info[i].0 <= time{
                package.push(info[i]);
            }
            else {
                cur = i;
                break;
            }
        }

        if package.len() == 0 {
            time += 1;
            ans.push(-1);
            continue;
        }

        
        let mut path = vec![];
        let mut c= 0;
        for p in &package{
            let g = p.2;
            mydbg!(p,g);
            loop{
                c = next[c][g];
                path.push(c);
                if c == g{
                    c = g;
                    break;
                }
            }
        }
        

        let g = 0;
        let mut c= package[package.len()-1].2;
        loop{
            c = next[c][g];
            path.push(c);
            if c == g{
                break;
            }
        }

        mydbg!(path);
        let mut b = 0;
        for item in &path{
            mydbg!(b,*item,dp[b][*item]);
            for _ in 0..dp[b][*item]{
                ans.push(*item as i32+1);
            }
            b = *item;
        }

        time += ans.len();
        if time >= tmax{
            break;
        }

    }

    for i in 0..tmax{
        println!("{}",ans[i]);
    }




}


Measured memory_bytes: 8444