// Try Hitachi Hokudai Labo & Hokkaido University Contest 2019-1
// author: Leonardone @ NEETSDKASU

struct SolverA {}

impl SolverA {
    fn new() -> Self {
        SolverA {}
    }
    fn get_commands(&self, problem: &Problem, new_orders: &[Vec<Order>]) -> Vec<Command> {
        vec![Command::Stay; problem.time_max]
    }
}

struct SolverB {}

impl SolverB {
    fn new() -> Self {
        SolverB {}
    }
    fn get_command(
        &mut self,
        problem: &Problem,
        new_orders: &[Order],
        put_orders: &[usize],
        achived_orders: &[usize],
    ) -> Command {
        Command::Stay
    }
}

fn main() {
    let io = StandardIO::new();
    let mut io = io.get_io();

    let problem = Problem::read(&mut io);

    if problem.is_interactive {
        let mut solver = SolverB::new();
        let mut achived_orders = vec![];
        for _ in 0..problem.time_max {
            let new_orders = read_new_orders(&mut io);
            let put_orders = read_put_orders(&mut io);
            let cmd = solver.get_command(&problem, &new_orders, &put_orders, &achived_orders);
            io.println(cmd);
            if io.gets() != "OK" {
                break;
            }
            achived_orders = read_achived_orders(&mut io);
        }
    } else {
        let mut new_orders = vec![];
        for _ in 0..problem.time_max {
            new_orders.push(read_new_orders(&mut io));
        }
        let solver = SolverA::new();
        let commands = solver.get_commands(&problem, &new_orders);
        for cmd in commands.iter() {
            io.println(cmd);
        }
    }
}

#[derive(Clone)]
enum Command {
    Move(usize),
    Stay,
}

impl std::fmt::Display for Command {
    fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
        match *self {
            Command::Move(v) => v.fmt(formatter),
            Command::Stay => "-1".fmt(formatter),
        }
    }
}

#[derive(Clone)]
struct Connection {
    vertex_id: usize,
    distance: usize,
}

impl Connection {
    fn new(i: usize, d: usize) -> Self {
        Connection {
            vertex_id: i,
            distance: d,
        }
    }
}

struct Problem {
    vertex_count: usize,
    graph: Vec<Vec<Connection>>,
    frequency: Vec<usize>,
    time_max: usize,
    is_interactive: bool,
}

impl Problem {
    fn read(io: &mut IO) -> Self {
        let (vc, ec) = io.get2();
        let mut g = vec![vec![]; vc + 1];
        for _ in 0..ec {
            let (u, v, d): (usize, usize, usize) = io.get3();
            g[u].push(Connection::new(v, d));
            g[v].push(Connection::new(u, d));
        }
        let freq = io.get_vec();
        let interacive = freq[0] == 0;
        let t_max = if !interacive { freq[0] } else { io.get() };
        Problem {
            vertex_count: vc,
            graph: g,
            frequency: freq,
            time_max: t_max,
            is_interactive: interacive,
        }
    }
}

struct Order {
    id: usize,
    destination: usize,
}

impl Order {
    fn new(i: usize, d: usize) -> Self {
        Order {
            id: i,
            destination: d,
        }
    }
}

fn read_new_orders(io: &mut IO) -> Vec<Order> {
    let mut orders = vec![];
    let n = io.get();
    for _ in 0..n {
        let (i, d) = io.get2();
        orders.push(Order::new(i, d));
    }
    orders
}

fn read_put_orders(io: &mut IO) -> Vec<usize> {
    let mut orders = vec![];
    let n = io.get();
    for _ in 0..n {
        orders.push(io.get());
    }
    orders
}

fn read_achived_orders(io: &mut IO) -> Vec<usize> {
    let mut orders = vec![];
    let n = io.get();
    for _ in 0..n {
        orders.push(io.get());
    }
    orders
}

struct StandardIO {
    stdin: std::io::Stdin,
    stdout: std::io::Stdout,
}

struct IO<'a> {
    stdin: std::io::StdinLock<'a>,
    stdout: std::io::StdoutLock<'a>,
}

impl StandardIO {
    fn new() -> Self {
        StandardIO {
            stdin: std::io::stdin(),
            stdout: std::io::stdout(),
        }
    }
    fn get_io(&self) -> IO {
        IO {
            stdin: self.stdin.lock(),
            stdout: self.stdout.lock(),
        }
    }
}

impl<'a> IO<'a> {
    fn get_line(&mut self) -> String {
        let mut line = String::new();
        std::io::BufRead::read_line(&mut self.stdin, &mut line).unwrap();
        line
    }
    fn gets(&mut self) -> String {
        self.get_line().trim().to_string()
    }
    fn get<A>(&mut self) -> A
    where
        A: std::str::FromStr,
        A::Err: std::fmt::Debug,
    {
        self.get_line().trim().parse().unwrap()
    }
    fn get2<A, B>(&mut self) -> (A, B)
    where
        A: std::str::FromStr,
        B: std::str::FromStr,
        A::Err: std::fmt::Debug,
        B::Err: std::fmt::Debug,
    {
        let line = self.get_line();
        let mut tokens = line.split_whitespace();
        let a: A = tokens.next().unwrap().parse().unwrap();
        let b: B = tokens.next().unwrap().parse().unwrap();
        (a, b)
    }
    fn get3<A, B, C>(&mut self) -> (A, B, C)
    where
        A: std::str::FromStr,
        B: std::str::FromStr,
        C: std::str::FromStr,
        A::Err: std::fmt::Debug,
        B::Err: std::fmt::Debug,
        C::Err: std::fmt::Debug,
    {
        let line = self.get_line();
        let mut tokens = line.split_whitespace();
        let a: A = tokens.next().unwrap().parse().unwrap();
        let b: B = tokens.next().unwrap().parse().unwrap();
        let c: C = tokens.next().unwrap().parse().unwrap();
        (a, b, c)
    }
    fn get_vec<A>(&mut self) -> Vec<A>
    where
        A: std::str::FromStr,
        A::Err: std::fmt::Debug,
    {
        self.get_line()
            .split_whitespace()
            .map(|v| v.parse().unwrap())
            .collect()
    }
    fn println<A: std::fmt::Display>(&mut self, v: A) {
        use std::io::Write;
        writeln!(&mut self.stdout, "{}", v).unwrap();
        self.stdout.flush().unwrap();
    }
}


Measured memory_bytes: 5456