One night, having had a hard day at work, Petya saw a nightmare. There was a binary search tree in the dream. But it was not the actual tree that scared Petya. The horrifying thing was that Petya couldn't search for elements in this tree. Petya tried many times to choose key and look for it in the tree, and each time he arrived at a wrong place. Petya has been racking his brains for long, choosing keys many times, but the result was no better. But the moment before Petya would start to despair, he had an epiphany: every time he was looking for keys, the tree didn't have the key, and occured exactly one mistake. "That's not a problem!", thought Petya. "Why not count the expectation value of an element, which is found when I search for the key". The moment he was about to do just that, however, Petya suddenly woke up.

Thus, you are given a binary search tree, that is a tree containing some number written in the node. This number is called the node key. The number of children of every node of the tree is equal either to 0 or to 2. The nodes that have 0 children are called leaves and the nodes that have 2 children, are called inner. An inner node has the left child, that is the child whose key is less than the current node's key, and the right child, whose key is more than the current node's key. Also, a key of any node is strictly larger than all the keys of the left subtree of the node and strictly smaller than all the keys of the right subtree of the node.

Also you are given a set of search keys, all of which are distinct and differ from the node keys contained in the tree. For each key from the set its search in the tree is realised. The search is arranged like this: initially we are located in the tree root, if the key of the current node is larger that our search key, then we move to the left child of the node, otherwise we go to the right child of the node and the process is repeated. As it is guaranteed that the search key is not contained in the tree, the search will always finish in some leaf. The key lying in the leaf is declared the search result.

It is known for sure that during the search we make a mistake in comparing exactly once, that is we go the wrong way, but we won't make any mistakes later. All possible mistakes are equiprobable, that is we should consider all such searches where exactly one mistake occurs. Your task is to find the expectation (the average value) of the search result for every search key, considering that exactly one mistake occurs in the search. That is, for a set of paths containing exactly one mistake in the given key search, you should count the average value of keys containing in the leaves of those paths.

Input

The first line contains an odd integer n (3 ≤ n < 105), which represents the number of tree nodes. Next n lines contain node descriptions. The (i + 1)-th line contains two space-separated integers. The first number is the number of parent of the i-st node and the second number is the key lying in the i-th node. The next line contains an integer k (1 ≤ k ≤ 105), which represents the number of keys for which you should count the average value of search results containing one mistake. Next k lines contain the actual keys, one key per line.

All node keys and all search keys are positive integers, not exceeding 109. All n + k keys are distinct.

All nodes are numbered from 1 to n. For the tree root "-1" (without the quote) will be given instead of the parent's node number. It is guaranteed that the correct binary search tree is given. For each node except for the root, it could be determined according to its key whether it is the left child or the right one.

Output

Print k real numbers which are the expectations of answers for the keys specified in the input. The answer should differ from the correct one with the measure of absolute or relative error not exceeding 10 - 9.

Examples

Input

7
-1 8
1 4
1 12
2 2
2 6
3 10
3 14
1
1


Output

8.0000000000


Input

3
-1 5
1 3
1 7
6
1
2
4
6
8
9


Output

7.0000000000
7.0000000000
7.0000000000
3.0000000000
3.0000000000
3.0000000000

Note

In the first sample the search of key 1 with one error results in two paths in the trees: (1, 2, 5) and (1, 3, 6), in parentheses are listed numbers of nodes from the root to a leaf. The keys in the leaves of those paths are equal to 6 and 10 correspondingly, that's why the answer is equal to 8.
import java.io.*;
import java.util.*;
import java.math.*;

public class C implements Runnable {

	static class Node {
		Node l;
		Node r;
		int x;
		boolean isLeaf;
		long sum;
		int max;
		int min;
		int path;

		public Node(int x) {
			sum = max = min = this.x = x;
			isLeaf = true;
		}
	}

	static void setChild(Node v, Node c) {
		if (v == null || c == null) {
			return;
		}
		v.isLeaf = false;
		if (v.x < c.x) {
			v.r = c;
		} else {
			v.l = c;
		}
	}

	static void countMinMax(Node v) {
		if (v.isLeaf) {
			return;
		}
		countMinMax(v.r);
		countMinMax(v.l);
		v.max = v.r.max;
		v.min = v.l.min;
	}

	static void countSum(Node v, long gotSum, int path) {
		if (v.isLeaf) {
			v.sum = gotSum;
			v.path = path;
			return;
		}
		countSum(v.l, gotSum + v.r.min, path + 1);
		countSum(v.r, v.l.max + gotSum, path + 1);
	}

	void solve() {
		int n = nextInt();
		Node[] nodes = new Node[n];
		int[] parents = new int[n];
		Map<Integer, Node> where = new HashMap<Integer, Node>();
		NavigableSet<Integer> what = new TreeSet<Integer>();
		for (int i = 0; i < n; i++) {
			parents[i] = nextInt();
			nodes[i] = new Node(nextInt());
			where.put(nodes[i].x, nodes[i]);
			what.add(nodes[i].x);
		}
		Node root = null;
		for (int i = 0; i < n; i++) {
			if (parents[i] == -1) {
				root = nodes[i];
				continue;
			}
			setChild(nodes[parents[i] - 1], nodes[i]);
		}
		countMinMax(root);
		countSum(root, 0, 0);
		int k = nextInt();
		for (int i = 0; i < k; i++) {
			int x = nextInt();
			Integer left = what.floor(x);
			Integer right = what.ceiling(x);
			if (left != null && where.get(left).isLeaf) {
				Node node = where.get(left);
				out.println(node.sum * 1. / node.path);
			} else {
				Node node = where.get(right);
				out.println(node.sum * 1. / node.path);
			}
		}
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	BigInteger nextBigInteger() {
		return sc.nextBigInteger();
	}

	class FastScanner extends BufferedReader {
		StringTokenizer st;
		boolean eof;
		String buf;
		String curLine;
		boolean createST;

		public FastScanner(String fileName) throws FileNotFoundException {
			this(fileName, true);
		}

		public FastScanner(String fileName, boolean createST)
				throws FileNotFoundException {
			super(new FileReader(fileName));
			this.createST = createST;
			nextToken();
		}

		public FastScanner(InputStream stream) {
			this(stream, true);
		}

		public FastScanner(InputStream stream, boolean createST) {
			super(new InputStreamReader(stream));
			this.createST = createST;
			nextToken();
		}

		String nextLine() {
			String ret = curLine;
			if (createST) {
				st = null;
			}
			nextToken();
			return ret;
		}

		String nextToken() {
			if (!createST) {
				try {
					curLine = readLine();
				} catch (Exception e) {
					eof = true;
				}
				return null;
			}
			while (st == null || !st.hasMoreTokens()) {
				try {
					curLine = readLine();
					st = new StringTokenizer(curLine);
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		BigInteger nextBigInteger() {
			return new BigInteger(nextToken());
		}

		public void close() {
			try {
				buf = null;
				st = null;
				curLine = null;
				super.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	public static void main(String[] args) {
		new C().run();
	}
}