fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

enum BTree {
    Empty,
    Node(u64, Box<BTree>, Box<BTree>),
}

impl BTree {
    fn from(v: &Vec<u64>) -> BTree {
        let l = v.len();
        BTree::from_sub(v, 0, l)
    }

    fn from_sub(v: &Vec<u64>, l: usize, r: usize) -> BTree {
        if l == r {
            BTree::Empty
        } else {
            let m = (l + r) / 2;
            BTree::Node(
                v[m],
                Box::new(BTree::from_sub(v, l, m)),
                Box::new(BTree::from_sub(v, m + 1, r)),
            )
        }
    }

    fn find_sup(&self, v: u64) -> Option<u64> {
        match *self {
            BTree::Empty => None,
            BTree::Node(ref x, ref l, ref r) => {
                if v == *x {
                    Some(*x)
                } else if *x < v {
                    r.find_sup(v)
                } else {
                    match l.find_sup(v) {
                        None => Some(*x),
                        Some(t) => Some(t),
                    }
                }
            }
        }
    }

    fn find_inf(&self, v: u64) -> Option<u64> {
        match *self {
            BTree::Empty => None,
            BTree::Node(ref x, ref l, ref r) => {
                if v == *x {
                    Some(*x)
                } else if *x > v {
                    l.find_inf(v)
                } else {
                    match r.find_inf(v) {
                        None => Some(*x),
                        Some(t) => Some(t),
                    }
                }
            }
        }
    }
}

fn min(x: u64, y: u64) -> u64 {
    if x < y {
        x
    } else {
        y
    }
}

fn diff(x: u64, y: u64) -> u64 {
    if x < y {
        y - x
    } else {
        x - y
    }
}

fn main() {
    let abq: Vec<usize> = read_vec();
    let s: Vec<u64> = read_col(abq[0]);
    let sbt = BTree::from(&s);
    let t: Vec<u64> = read_col(abq[1]);
    let tbt = BTree::from(&t);
    let xv: Vec<u64> = read_col(abq[2]);

    for x in xv {
        let mut sv: Vec<u64> = vec![];
        let mut tv: Vec<u64> = vec![];

        if let Some(x) = sbt.find_inf(x) {
            sv.push(x);
        }
        if let Some(x) = sbt.find_sup(x) {
            sv.push(x);
        }

        if let Some(x) = tbt.find_inf(x) {
            tv.push(x);
        }
        if let Some(x) = tbt.find_sup(x) {
            tv.push(x);
        }

        let mut ans: u64 = 100000000000;

        for s in &sv {
            for t in &tv {
                let tmp = diff(*s, *t) + min(diff(x, *s), diff(x, *t));
                if tmp < ans {
                    ans = tmp;
                }
            }
        }

        println!("{}", ans);
    }
}


Measured memory_bytes: 19708