use std::{ cmp::Reverse, collections::BinaryHeap, fmt::Binary, io::{read_to_string, stdin}, }; fn main() { let mut line = String::new(); let mut heap = BinaryHeap::new(); loop { line.clear(); stdin().read_line(&mut line).unwrap(); if line.starts_with('#') { break; } let mut iter = line.trim().split(' '); iter.next(); let q = iter.next().unwrap().parse::().unwrap(); let p = iter.next().unwrap().parse::().unwrap(); heap.push(Reverse((p, q, p))) } line.clear(); stdin().read_line(&mut line).unwrap(); let k = line.trim().parse::().unwrap(); for i in 0..k { let (curr, q, period) = (heap.pop().unwrap()).0; heap.push(Reverse((curr + period, q, period))); println!("{}", q); } }