use std::io::BufRead;
use std::cmp::max;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}

impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap();
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone())
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone(), tmp_var[2].clone())
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}

fn main() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());

    let n: usize = input!(r, usize);
    let mut phrases: Vec<(usize, usize, usize)> = vec![(0, 0, 0)];
    for i in 0..n {
        phrases.push(input!(r, usize, usize, usize));
    }

    let mut memo: Vec<Vec<usize>> = vec![vec![0; 394]; n + 1];
    for i in 1..n + 1 {
        let minimum = phrases[i].0;
        let maximum = phrases[i].1;
        let point = phrases[i].2;
        for j in 0..394 {
            for k in minimum..maximum + 1 {
                if k > j {
                    memo[i][j] = max(memo[i - 1][j], memo[i][j]);
                } else {
                    memo[i][j] =
                        max(memo[i][j],
                            max(memo[i - 1][j], memo[i][j - k] + point));
                }
            }
        }
    }
    let m: usize = input!(r, usize);
    let melodies: Vec<usize> = (0..m)
        .map(|_| memo[n][input!(r, usize)]).collect();
    if melodies.iter().filter(|&&p| p == 0).count() > 0 {
        println!("-1");
    } else {
        for p in melodies {
            println!("{}", p);
        }
    }
}




Measured memory_bytes: 5048