use std::collections::VecDeque;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut graph = vec![vec![]; n];
    let mut edges = vec![];
    for i in 0..(n - 1) {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push((b, i));
        graph[b].push((a, i));
        edges.push((a, b));
    }

    let m: usize = sc.read();
    let mut rules = vec![];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        let edges = mark(&graph, a, b);
        rules.push(edges);
    }

    let mut edge_rule = vec![vec![]; n - 1];
    for rule_id in 0..m {
        for &edge_id in rules[rule_id].iter() {
            edge_rule[edge_id].push(rule_id);
        }
    }

    let mut dp: Vec<Vec<i64>> = vec![vec![0; 1 << m]; n];
    dp[0][0] = 1;
    for edge_id in 0..(n - 1) {
        let mut edge_mask = 0;
        for &rule in edge_rule[edge_id].iter() {
            edge_mask |= 1 << rule;
        }
        //        println!("mask={}", edge_mask);

        for cur_mask in 0..(1 << m) {
            dp[edge_id + 1][cur_mask] += dp[edge_id][cur_mask];
            dp[edge_id + 1][cur_mask | edge_mask] += dp[edge_id][cur_mask];
        }
    }

    println!("{}", dp[n - 1][(1 << m) - 1]);
    //    eprintln!("{:?}", dp);
}

fn mark(graph: &Vec<Vec<(usize, usize)>>, from: usize, to: usize) -> Vec<usize> {
    let mut edges = vec![];
    let n = graph.len();
    let mut dist: Vec<i64> = vec![1 << 50; n];
    let mut q = VecDeque::new();
    q.push_back(from);
    dist[from] = 0;
    while let Some(v) = q.pop_front() {
        for &(next, _) in graph[v].iter() {
            if dist[next] > dist[v] + 1 {
                dist[next] = dist[v] + 1;
                q.push_back(next);
            }
        }
    }

    let mut q = VecDeque::new();
    q.push_back(to);
    while let Some(v) = q.pop_front() {
        for &(next, id) in graph[v].iter() {
            if dist[v] > dist[next] {
                edges.push(id);
                q.push_back(next);
            }
        }
    }
    edges
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 413948