Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree?

Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wanted to see if similar techniques in trees can be used in 1-trees as well. Instead of solving it by himself, he's going to test you by providing queries on 1-trees.

First, he'll provide you a tree (not 1-tree) with $n$ vertices, then he will ask you $q$ queries. Each query contains $5$ integers: $x$, $y$, $a$, $b$, and $k$. This means you're asked to determine if there exists a path from vertex $a$ to $b$ that contains exactly $k$ edges after adding a bidirectional edge between vertices $x$ and $y$. A path can contain the same vertices and same edges multiple times. All queries are independent of each other; i.e. the added edge in a query is removed in the next query.


-----Input-----

The first line contains an integer $n$ ($3 \le n \le 10^5$), the number of vertices of the tree.

Next $n-1$ lines contain two integers $u$ and $v$ ($1 \le u,v \le n$, $u \ne v$) each, which means there is an edge between vertex $u$ and $v$. All edges are bidirectional and distinct.

Next line contains an integer $q$ ($1 \le q \le 10^5$), the number of queries Gildong wants to ask.

Next $q$ lines contain five integers $x$, $y$, $a$, $b$, and $k$ each ($1 \le x,y,a,b \le n$, $x \ne y$, $1 \le k \le 10^9$) – the integers explained in the description. It is guaranteed that the edge between $x$ and $y$ does not exist in the original tree.


-----Output-----

For each query, print "YES" if there exists a path that contains exactly $k$ edges from vertex $a$ to $b$ after adding an edge between vertices $x$ and $y$. Otherwise, print "NO".

You can print each letter in any case (upper or lower).


-----Example-----
Input
5
1 2
2 3
3 4
4 5
5
1 3 1 2 2
1 4 1 3 2
1 4 1 3 3
4 2 3 3 9
5 2 3 3 9

Output
YES
YES
NO
YES
NO



-----Note-----

The image below describes the tree (circles and solid lines) and the added edges for each query (dotted lines). [Image] 

Possible paths for the queries with "YES" answers are:   $1$-st query: $1$ – $3$ – $2$  $2$-nd query: $1$ – $2$ – $3$  $4$-th query: $3$ – $4$ – $2$ – $3$ – $4$ – $2$ – $3$ – $4$ – $2$ – $3$

Source: codeforces | Difficulty: MEDIUM


Solutions:
from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
from collections import namedtuple
Path = namedtuple('Path', 'length midlength middle left right')
(n,) = rl()
adj = [[] for _ in range(n + 1)]
paths = [None for _ in range(n + 1)]
for _ in range(n - 1):
	(u, v) = rl()
	adj[u].append(v)
	adj[v].append(u)

def append(path, x):
	if not path:
		return Path(1, 1, x, None, None)
	l = path.length + 1
	if l >= 2 * path.midlength:
		return Path(l, path.midlength * 2, x, path, None)
	else:
		return Path(l, path.midlength, path.middle, path.left, append(path.right, x))
queue = [(1, 0)]
for i in range(n):
	(v, parent) = queue[i]
	paths[v] = append(paths[parent], v)
	for u in adj[v]:
		if u != parent:
			queue.append((u, v))

def gcp(x, y):
	if not x or not y:
		return 0
	while x.midlength > y.midlength:
		x = x.left
	while y.midlength > x.midlength:
		y = y.left
	if x.middle == y.middle:
		return x.midlength + gcp(x.right, y.right)
	else:
		return gcp(x.left, y.left)

def dist(x, y):
	px = paths[x]
	py = paths[y]
	return px.length + py.length - 2 * gcp(px, py)
(q,) = rl()
for _ in range(q):
	(x, y, a, b, k) = rl()
	ds = [dist(a, b), dist(a, x) + 1 + dist(y, b), dist(a, y) + 1 + dist(x, b)]
	for d in ds:
		if k >= d and (k - d) % 2 == 0:
			print('YES')
			break
	else:
		print('NO')


def main():
	import sys
	input = sys.stdin.buffer.readline

	class SegTree:

		def __init__(self, N):
			self.N0 = 2 ** (N - 1).bit_length()
			self.INF = 2000000000
			self.seg_min = [self.INF] * (2 * self.N0)

		def update(self, index, value):
			index += self.N0 - 1
			self.seg_min[index] = value
			while index > 0:
				index = (index - 1) // 2
				self.seg_min[index] = min(self.seg_min[index * 2 + 1], self.seg_min[index * 2 + 2])

		def query(self, first, last):
			first += self.N0 - 1
			last += self.N0 - 1
			ret = self.INF
			while first <= last:
				if not first & 1:
					ret = min(ret, self.seg_min[first])
				if last & 1:
					ret = min(ret, self.seg_min[last])
				first = first // 2
				last = last // 2 - 1
			return ret

	def EulerTour(adj, root):
		st = [root]
		ret = []
		seen = [0] * len(adj)
		par = [0] * len(adj)
		depth = [0] * len(adj)
		while st:
			v = st.pop()
			if seen[v]:
				ret.append(v)
				continue
			ret.append(v)
			seen[v] = 1
			if par[v] != 0:
				st.append(par[v])
			for u in adj[v]:
				if seen[u] == 0:
					st.append(u)
					par[u] = v
					depth[u] = depth[v] + 1
		return (ret, depth)
	N = int(input())
	adj = [[] for _ in range(N + 1)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		adj[a].append(b)
		adj[b].append(a)
	(et, depth) = EulerTour(adj, 1)
	segtree = SegTree(len(et) + 1)
	left = [-1] * (N + 1)
	right = [-1] * (N + 1)
	for (i, v) in enumerate(et):
		segtree.update(i + 1, depth[v])
		if left[v] < 0:
			left[v] = i
		right[v] = i
	q = int(input())
	for i in range(q):
		(x, y, a, b, k) = map(int, input().split())
		lca_depth_AB = segtree.query(min(left[a], left[b]) + 1, max(right[a], right[b]) + 1)
		AB = depth[a] + depth[b] - 2 * lca_depth_AB
		if k >= AB and (k - AB) % 2 == 0:
			print('YES')
			continue
		lca_depth_AX = segtree.query(min(left[a], left[x]) + 1, max(right[a], right[x]) + 1)
		AX = depth[a] + depth[x] - 2 * lca_depth_AX
		lca_depth_BY = segtree.query(min(left[b], left[y]) + 1, max(right[b], right[y]) + 1)
		BY = depth[b] + depth[y] - 2 * lca_depth_BY
		AB_new = AX + BY + 1
		if k >= AB_new and (k - AB_new) % 2 == 0:
			print('YES')
			continue
		lca_depth_AY = segtree.query(min(left[a], left[y]) + 1, max(right[a], right[y]) + 1)
		AY = depth[a] + depth[y] - 2 * lca_depth_AY
		lca_depth_BX = segtree.query(min(left[b], left[x]) + 1, max(right[b], right[x]) + 1)
		BX = depth[b] + depth[x] - 2 * lca_depth_BX
		AB_new = AY + BX + 1
		if k >= AB_new and (k - AB_new) % 2 == 0:
			print('YES')
			continue
		print('NO')
main()


def lca(u, v):
	if h[u] < h[v]:
		(u, v) = (v, u)
	for i in range(h[u].bit_length() - 1, -1, -1):
		if par[u][i] != -1 and h[par[u][i]] >= h[v]:
			u = par[u][i]
	if u == v:
		return u
	for i in range(h[u].bit_length() - 1, -1, -1):
		if par[u][i] != par[v][i]:
			u = par[u][i]
			v = par[v][i]
	return par[u][0]

def dist(u, v):
	lc = lca(u, v)
	return h[u] - h[lc] + h[v] - h[lc]

def cal(x, y, a, b, k):
	d = dist(a, b)
	if d <= k and k - d & 1 == 0:
		return True
	d = dist(a, x) + 1 + dist(y, b)
	if d <= k and k - d & 1 == 0:
		return True
	d = dist(a, y) + 1 + dist(x, b)
	if d <= k and k - d & 1 == 0:
		return True

def dfs(u, p=-1):
	stack = [(u, p)]
	while stack:
		(u, p) = stack.pop()
		par[u][0] = p
		if p != -1:
			h[u] = h[p] + 1
		for i in range(1, LN):
			if par[u][i - 1] != -1:
				par[u][i] = par[par[u][i - 1]][i - 1]
		for v in adj[u]:
			if v != p:
				stack.append((v, u))
n = int(input())
h = [0] * n
LN = (n - 1).bit_length()
par = [[-1] * LN for _ in range(n)]
adj = [[] for _ in range(n)]
vs = (map(int, input().split()) for _ in range(n - 1))
for (u, v) in vs:
	u -= 1
	v -= 1
	adj[u].append(v)
	adj[v].append(u)
dfs(0)
q = int(input())
for _ in range(q):
	(x, y, a, b, k) = map(int, input().split())
	print('YES' if cal(x - 1, y - 1, a - 1, b - 1, k) else 'NO')


import os, sys
from io import BytesIO, IOBase

def euler_path(n, path):
	height = [0] * n + [10 ** 10]
	(euler, st, visi, he) = ([], [0], [1] + [0] * (n - 1), 0)
	first = [-1] * n
	while len(st):
		x = st[-1]
		euler.append(x)
		if first[x] == -1:
			first[x] = len(euler) - 1
		while len(path[x]) and visi[path[x][-1]]:
			path[x].pop()
		if not len(path[x]):
			he -= 1
			st.pop()
		else:
			i = path[x].pop()
			he += 1
			st.append(i)
			(height[i], visi[i]) = (he, 1)
	return (height, euler, first)

def cons(euler, height):
	n = len(euler)
	xx = n.bit_length()
	dp = [[n] * n for _ in range(xx)]
	dp[0] = euler
	for i in range(1, xx):
		for j in range(n - (1 << i) + 1):
			(a, b) = (dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
			dp[i][j] = a if height[a] < height[b] else b
	return dp

def lca(l, r, dp, height, first):
	(l, r) = (first[l], first[r])
	if l > r:
		(l, r) = (r, l)
	xx1 = (r - l + 1).bit_length() - 1
	(a, b) = (dp[xx1][l], dp[xx1][r - (1 << xx1) + 1])
	return a if height[a] < height[b] else b

def dis(a, b, dp, height, first):
	return height[a] + height[b] - 2 * height[lca(a, b, dp, height, first)]

def main():
	n = int(input())
	path = [[] for _ in range(n)]
	for _ in range(n - 1):
		(u1, v1) = map(int, input().split())
		path[u1 - 1].append(v1 - 1)
		path[v1 - 1].append(u1 - 1)
	(height, euler, first) = euler_path(n, path)
	dp = cons(euler, height)
	for _ in range(int(input())):
		(x, y, a, b, k) = map(lambda xx: int(xx) - 1, input().split())
		k += 1
		z = dis(a, b, dp, height, first)
		z1 = dis(a, x, dp, height, first) + 1 + dis(y, b, dp, height, first)
		z2 = dis(a, y, dp, height, first) + 1 + dis(x, b, dp, height, first)
		if z <= k and z & 1 == k & 1:
			print('YES')
		elif z1 <= k and z1 & 1 == k & 1:
			print('YES')
		elif z2 <= k and z2 & 1 == k & 1:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, os

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		depth = (end - begin).bit_length() - 1
		return self.func(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, root, graph):
		self.time = [-1] * len(graph)
		self.path = [-1] * len(graph)
		P = [-1] * len(graph)
		t = -1
		dfs = [root]
		while dfs:
			node = dfs.pop()
			self.path[t] = P[node]
			self.time[node] = t = t + 1
			for nei in graph[node]:
				if self.time[nei] == -1:
					P[nei] = node
					dfs.append(nei)
		self.rmq = RangeQuery((self.time[node] for node in self.path))

	def __call__(self, a, b):
		if a == b:
			return a
		a = self.time[a]
		b = self.time[b]
		if a > b:
			(a, b) = (b, a)
		return self.path[self.rmq.query(a, b)]
inp = [int(x) for x in sys.stdin.buffer.read().split()]
ii = 0
n = inp[ii]
ii += 1
coupl = [[] for _ in range(n)]
for _ in range(n - 1):
	u = inp[ii] - 1
	ii += 1
	v = inp[ii] - 1
	ii += 1
	coupl[u].append(v)
	coupl[v].append(u)
root = 0
lca = LCA(root, coupl)
depth = [-1] * n
depth[root] = 0
bfs = [root]
for node in bfs:
	for nei in coupl[node]:
		if depth[nei] == -1:
			depth[nei] = depth[node] + 1
			bfs.append(nei)

def dist(a, b):
	c = lca(a, b)
	return depth[a] + depth[b] - 2 * depth[c]
q = inp[ii]
ii += 1
out = []
for _ in range(q):
	x = inp[ii] - 1
	ii += 1
	y = inp[ii] - 1
	ii += 1
	a = inp[ii] - 1
	ii += 1
	b = inp[ii] - 1
	ii += 1
	k = inp[ii]
	ii += 1
	shortest_odd = 10 ** 9 + 11
	shortest_even = 10 ** 9 + 10
	for d in [dist(a, b), dist(a, x) + dist(y, b) + 1, dist(a, y) + dist(x, b) + 1, dist(a, b) + dist(b, x) + dist(y, b) + 1, dist(b, a) + dist(a, x) + dist(y, a) + 1]:
		if d & 1:
			shortest_odd = min(shortest_odd, d)
		else:
			shortest_even = min(shortest_even, d)
	if k & 1:
		out.append(b'YES' if shortest_odd <= k else b'NO')
	else:
		out.append(b'YES' if shortest_even <= k else b'NO')
os.write(1, b'\n'.join(out))


import sys, math
import io, os
data = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = int(1000000000.0) + 7
INF = 10 ** 8

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		depth = (end - begin).bit_length() - 1
		return self.func(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, root, graph):
		self.time = [-1] * len(graph)
		self.path = [-1] * len(graph)
		self.depth = [0] * len(graph)
		P = [-1] * len(graph)
		t = -1
		dfs = [root]
		while dfs:
			node = dfs.pop()
			self.path[t] = P[node]
			self.time[node] = t = t + 1
			for nei in graph[node]:
				if self.time[nei] == -1:
					P[nei] = node
					dfs.append(nei)
					self.depth[nei] = self.depth[node] + 1
		self.rmq = RangeQuery((self.time[node] for node in self.path))

	def __call__(self, a, b):
		if a == b:
			return a
		a = self.time[a]
		b = self.time[b]
		if a > b:
			(a, b) = (b, a)
		return self.path[self.rmq.query(a, b)]

def dis(a, b):
	return L.depth[a] + L.depth[b] - 2 * L.depth[L(a, b)]
n = int(data())
graph = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = mdata()
	graph[u - 1].append(v - 1)
	graph[v - 1].append(u - 1)
L = LCA(0, graph)
ans = []
for i in range(int(data())):
	(x, y, a, b, k) = mdata()
	(x, y, a, b) = (x - 1, y - 1, a - 1, b - 1)
	flag = True
	for d in [dis(a, b), dis(a, x) + dis(b, y) + 1, dis(a, y) + dis(b, x) + 1]:
		if d <= k and d % 2 == k % 2:
			out('YES')
			flag = False
			break
	if flag:
		out('NO')


import sys
inp = sys.stdin.readline

def input():
	return inp().strip()
out = []

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))
INF = 10 ** 5 + 7
n = iin()
adj = [[] for i in range(n + 1)]
for _ in range(n - 1):
	(i, j) = lin()
	adj[i].append(j)
	adj[j].append(i)

def dfs(adj, start=1):
	n = len(adj)
	visited = [False] * n
	first = [-1] * n
	euler = []
	height = [-1] * n
	srt = [start]
	height[start] = 1
	parent = [-1] * n
	while srt:
		v = srt.pop()
		if visited[v]:
			euler.append(v)
			continue
		first[v] = len(euler)
		euler.append(v)
		visited[v] = True
		if parent[v] != -1:
			srt.append(parent[v])
		for u in adj[v]:
			if not visited[u]:
				parent[u] = v
				height[u] = height[v] + 1
				srt.append(u)
	return (first, euler, height)
(first, euler, height) = dfs(adj)
euler = [height[i] for i in euler]
__tree_length = len(euler)
segment_tree = [-1] * (__tree_length * 4 + 1)
segment_tree_left = [-1] * (__tree_length * 4 + 1)
segment_tree_right = [-1] * (__tree_length * 4 + 1)

def set_segment_tree(x, val, l, r):
	segment_tree[x] = val
	segment_tree_left[x] = l
	segment_tree_right[x] = r

def build(l=0, r=len(euler) - 1, x=1):
	if l == r:
		set_segment_tree(x, euler[l], l, r)
	else:
		m = l + r >> 1
		left = build(l, m, x << 1)
		right = build(m + 1, r, x << 1 | 1)
		val = min(left, right)
		set_segment_tree(x, val, l, r)
	return segment_tree[x]

def query(l, r, x=1):
	(val, L, R) = (segment_tree[x], segment_tree_left[x], segment_tree_right[x])
	if l <= L and R <= r:
		return val
	elif r < L or l > R:
		return INF
	else:
		left = query(l, r, x << 1)
		right = query(l, r, x << 1 | 1)
		return min(left, right)
build()

def check(i, j):
	(l, r) = (first[i], first[j])
	if l > r:
		(l, r) = (r, l)
	h = query(l, r)
	return height[i] + height[j] - 2 * h
q = iin()
while q:
	q -= 1
	(x, y, a, b, k) = lin()
	ans1 = [check(a, b), check(a, x) + 1 + check(y, b), check(a, y) + 1 + check(x, b)]
	for i in ans1:
		if k - i >= 0 and (k - i) % 2 == 0:
			out.append('YES')
			break
	else:
		out.append('NO')
print('\n'.join(out))


import sys
inp = sys.stdin.buffer.readline

def input():
	return inp().strip()
out = []

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))
INF = 10 ** 5 + 7
n = iin()
adj = [[] for i in range(n + 1)]
for _ in range(n - 1):
	(i, j) = lin()
	adj[i].append(j)
	adj[j].append(i)

def dfs(adj, start=1):
	n = len(adj)
	visited = [False] * n
	first = [-1] * n
	euler = []
	height = [-1] * n
	srt = [start]
	height[start] = 1
	parent = [-1] * n
	while srt:
		v = srt.pop()
		if visited[v]:
			euler.append(v)
			continue
		first[v] = len(euler)
		euler.append(v)
		visited[v] = True
		if parent[v] != -1:
			srt.append(parent[v])
		for u in adj[v]:
			if not visited[u]:
				parent[u] = v
				height[u] = height[v] + 1
				srt.append(u)
	return (first, euler, height)
(first, euler, height) = dfs(adj)
euler = [height[i] for i in euler]

class Sparse_Table:

	def __init__(self, arr):
		from math import log
		self.arr = arr
		self.n = len(arr)
		self.logfn = lambda x: log(x, 2)
		self.table = self.build()

	def build(self):
		n = self.n
		sz = int(self.logfn(n)) + 1
		st = [[INF for i in range(sz)] for j in range(n)]
		for i in range(n):
			st[i][0] = self.arr[i]
		for i in range(1, sz):
			step = pow(2, i - 1)
			for j in range(n - step * 2 + 1):
				st[j][i] = min(st[j + step][i - 1], st[j][i - 1])
		return st

	def query(self, begin, end):
		end += 1
		depth = (end - begin).bit_length() - 1
		return min(self.table[begin][depth], self.table[end - (1 << depth)][depth])
sa = Sparse_Table(euler)

def check(i, j):
	(l, r) = (first[i], first[j])
	if l > r:
		(l, r) = (r, l)
	h = sa.query(l, r)
	return height[i] + height[j] - 2 * h
q = iin()
while q:
	q -= 1
	(x, y, a, b, k) = lin()
	ans1 = [check(a, b), check(a, x) + 1 + check(y, b), check(a, y) + 1 + check(x, b)]
	for i in ans1:
		if k - i >= 0 and (k - i) % 2 == 0:
			out.append('YES')
			break
	else:
		out.append('NO')
print('\n'.join(out))


import sys
input = sys.stdin.readline
N = int(input())
G = [set() for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	G[a].add(b)
	G[b].add(a)
S = [None] * (2 * N - 1)
F = [None] * (N + 1)
stack = [1]
visited = set()
depth = [None] * (N + 1)
depth[1] = 0
ii = 0
while stack:
	v = stack.pop()
	if v > 0:
		visited.add(v)
		(F[v], S[ii]) = (ii, v)
		ii += 1
		for u in G[v]:
			if u in visited:
				continue
			stack += [-v, u]
			depth[u] = depth[v] + 1
	else:
		S[ii] = -v
		ii += 1
INF = (N, None)
M = 2 * N
M0 = 2 ** (M - 1).bit_length()
data = [INF] * (2 * M0)
for (i, v) in enumerate(S):
	data[M0 - 1 + i] = (depth[v], i)
for i in range(M0 - 2, -1, -1):
	data[i] = min(data[2 * i + 1], data[2 * i + 2])

def _query(a, b):
	yield INF
	(a, b) = (a + M0, b + M0)
	while a < b:
		if b & 1:
			b -= 1
			yield data[b - 1]
		if a & 1:
			yield data[a - 1]
			a += 1
		(a, b) = (a >> 1, b >> 1)

def query(u, v):
	(fu, fv) = (F[u], F[v])
	if fu > fv:
		(fu, fv) = (fv, fu)
	return S[min(_query(fu, fv + 1))[1]]

def dist(x, y):
	c = query(x, y)
	return depth[x] + depth[y] - 2 * depth[c]
Q = int(input())
for _ in range(Q):
	(x, y, a, b, k) = map(int, input().split())
	t1 = dist(a, b)
	t2 = min(dist(a, x) + dist(y, b), dist(a, y) + dist(x, b)) + 1
	if t1 <= k and (t1 - k) % 2 == 0 or (t2 <= k and (t2 - k) % 2 == 0):
		print('YES')
	else:
		print('NO')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from collections import deque

class LCA:

	def __init__(self, G, root):
		self.n = len(G)
		self.dep = [0] * self.n
		self.par = [[-1] * self.n for i in range(18)]

		def bfs(root):
			que = deque()
			que.append((-1, root, 0))
			while que:
				(p, v, d) = que.pop()
				self.dep[v] = d
				self.par[0][v] = p
				for to in G[v]:
					if to != p:
						que.append((v, to, d + 1))
		bfs(root)
		for i in range(17):
			for j in range(self.n):
				self.par[i + 1][j] = self.par[i][self.par[i][j]]

	def lca(self, a, b):
		if self.dep[a] > self.dep[b]:
			(a, b) = (b, a)
		for i in range(18):
			if self.dep[b] - self.dep[a] & 1 << i:
				b = self.par[i][b]
		if a == b:
			return a
		for i in range(18)[::-1]:
			if self.par[i][a] != self.par[i][b]:
				a = self.par[i][a]
				b = self.par[i][b]
		return self.par[0][a]

	def dist(self, a, b):
		lca = self.lca(a, b)
		return self.dep[a] + self.dep[b] - 2 * self.dep[lca]
n = int(input())
G = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	G[a].append(b)
	G[b].append(a)
L = LCA(G, 0)
q = int(input())
for i in range(q):
	(x, y, a, b, k) = map(int, input().split())
	(x, y, a, b) = (x - 1, y - 1, a - 1, b - 1)
	ab = L.dist(a, b)
	base = [ab]
	ax = L.dist(a, x)
	ay = L.dist(a, y)
	bx = L.dist(b, x)
	by = L.dist(b, y)
	base.append(ax + 1 + by)
	base.append(ay + 1 + bx)
	flag = any((ki <= k and (k - ki) % 2 == 0 for ki in base))
	if flag:
		print('YES')
	else:
		print('NO')


import sys

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		depth = (end - begin).bit_length() - 1
		return self.func(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, root, graph):
		self.time = [-1] * len(graph)
		self.path = []
		self.depth = [0] * len(graph)
		dfs = [root]
		while dfs:
			node = dfs.pop()
			self.path.append(node)
			if self.time[node] == -1:
				self.time[node] = len(self.path) - 1
				for nei in graph[node]:
					if self.time[nei] == -1:
						self.depth[nei] = self.depth[node] + 1
						dfs.append(node)
						dfs.append(nei)
		self.rmq = RangeQuery((self.time[node] for node in self.path))

	def lca(self, a, b):
		a = self.time[a]
		b = self.time[b]
		if a > b:
			(a, b) = (b, a)
		return self.path[self.rmq.query(a, b + 1)]

def solve(N, edges, queries):
	graph = [[] for i in range(N + 1)]
	for e in edges:
		graph[e[0]].append(e[1])
		graph[e[1]].append(e[0])
	L = LCA(1, graph)

	def lca(u, v):
		return L.lca(u, v)

	def getDist(u, v):
		return L.depth[u] + L.depth[v] - 2 * L.depth[lca(u, v)]
	ans = []
	for (x, y, a, b, k) in queries:
		d_ab = getDist(a, b)
		d_axyb = getDist(a, x) + 1 + getDist(y, b)
		d_ayxb = getDist(a, y) + 1 + getDist(x, b)
		if any((d <= k and (k - d) % 2 == 0 for d in [d_ab, d_axyb, d_ayxb])):
			ans.append('YES')
		else:
			ans.append('NO')
	return '\n'.join(ans)
N = int(input())
edges = []
for i in range(N - 1):
	edges.append(list(map(int, sys.stdin.readline().split())))
Q = int(input())
queries = []
for i in range(Q):
	queries.append(list(map(int, sys.stdin.readline().split())))
ans = solve(N, edges, queries)
print(ans)


import sys
from collections import deque
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(v, to) = map(int, input().split())
	v -= 1
	to -= 1
	g[v].append(to)
	g[to].append(v)
root = 0
visited = [False] * n
cs = [[] for _ in range(n)]
queue = deque([root])
while queue:
	v = queue.popleft()
	if not visited[v]:
		visited[v] = True
		for to in g[v]:
			cs[v].append(to)
			queue.append(to)
visited = [False] * n
stack = [(0, root)]
traversal = []
enters = [-1] * n
while stack:
	(depth, v) = stack.pop()
	if not visited[v]:
		visited[v] = True
		enters[v] = len(traversal)
		for child in cs[v]:
			stack.append((depth, v))
			stack.append((depth + 1, child))
	traversal.append((depth, v))
N = len(traversal)
k = 1
while 1 << k < N:
	k += 1
ST = [[float('inf')] * k for _ in range(N)]
for i in range(N):
	ST[i][0] = traversal[i]
for j in range(1, k):
	for i in range(N):
		if i + (1 << j) > N:
			continue
		ST[i][j] = min(ST[i][j - 1], ST[i + (1 << j - 1)][j - 1])
log_len = [0] * (N + 1)
for i in range(2, N + 1):
	log_len[i] = log_len[i >> 1] + 1
q = int(input())
ans = []
for _ in range(q):
	(x, y, a, b, k) = map(int, input().split())
	x -= 1
	y -= 1
	a -= 1
	b -= 1
	Ia = enters[a]
	Ib = enters[b]
	(da, _) = traversal[Ia]
	(db, _) = traversal[Ib]
	L = min(Ia, Ib)
	R = max(Ia, Ib)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	curr = da - depth + db - depth
	if curr <= k and (k - curr) % 2 == 0:
		print('YES')
		continue
	Ix = enters[x]
	Iy = enters[y]
	(dx, _) = traversal[Ix]
	(dy, _) = traversal[Iy]
	L = min(Ia, Ix)
	R = max(Ia, Ix)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	part_ax = da - depth + dx - depth
	L = min(Ib, Iy)
	R = max(Ib, Iy)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	part_by = db - depth + dy - depth
	curr = part_ax + 1 + part_by
	if curr <= k and (k - curr) % 2 == 0:
		print('YES')
		continue
	L = min(Ia, Iy)
	R = max(Ia, Iy)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	part_ay = da - depth + dy - depth
	L = min(Ib, Ix)
	R = max(Ib, Ix)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	part_bx = db - depth + dx - depth
	curr = part_ay + 1 + part_bx
	if curr <= k and (k - curr) % 2 == 0:
		print('YES')
		continue
	print('NO')


class Doubling:

	def __init__(self, graph, rootNode=0):
		self.graph = graph
		self.N = len(graph)
		self.Log_N = (self.N - 1).bit_length()
		self.rootNode = rootNode
		self.prev = [None] * self.N
		self.Depth = [-1] * self.N
		q = [self.rootNode]
		self.Depth[self.rootNode] = 0
		d = 0
		while q:
			qq = []
			d += 1
			for p in q:
				for np in self.graph[p]:
					if self.Depth[np] == -1:
						self.prev[np] = p
						self.Depth[np] = d
						qq.append(np)
			q = qq
		self.kprev = [self.prev]
		S = self.prev
		for k in range(self.Log_N):
			T = [None] * self.N
			for i in range(self.N):
				if S[i] is None:
					continue
				T[i] = S[S[i]]
			self.kprev.append(T)
			S = T

	def LCAquery(self, u, v):
		dd = self.Depth[v] - self.Depth[u]
		if dd < 0:
			(u, v) = (v, u)
			dd = -dd
		for k in range(self.Log_N + 1):
			if dd & 1:
				v = self.kprev[k][v]
			dd >>= 1
		if u == v:
			return u
		for k in reversed(range(self.Log_N)):
			pu = self.kprev[k][u]
			pv = self.kprev[k][v]
			if pu != pv:
				(u, v) = (pu, pv)
		return self.kprev[0][u]
import sys
input = sys.stdin.readline
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
Q = int(input())
Query = []
for _ in range(Q):
	(x, y, a, b, k) = map(int, input().split())
	Query.append((x - 1, y - 1, a - 1, b - 1, k))
doubling = Doubling(graph)

def solve(x, y, a, b, k):
	d_a = doubling.Depth[a]
	d_b = doubling.Depth[b]
	d_x = doubling.Depth[x]
	d_y = doubling.Depth[y]
	lca_ab = doubling.LCAquery(a, b)
	d_ab = d_a + d_b - 2 * doubling.Depth[lca_ab]
	lca_ax = doubling.LCAquery(a, x)
	d_ax = d_x + d_a - 2 * doubling.Depth[lca_ax]
	lca_yb = doubling.LCAquery(y, b)
	d_yb = d_y + d_b - 2 * doubling.Depth[lca_yb]
	lca_ay = doubling.LCAquery(a, y)
	d_ay = d_y + d_a - 2 * doubling.Depth[lca_ay]
	lca_xb = doubling.LCAquery(x, b)
	d_xb = d_x + d_b - 2 * doubling.Depth[lca_xb]
	Ds = [d_ab, d_ax + d_yb + 1, d_ay + d_xb + 1]
	for d in Ds:
		if d <= k and (k - d) % 2 == 0:
			return True
	return False
for (x, y, a, b, k) in Query:
	ok = solve(x, y, a, b, k)
	print('YES' if ok else 'NO')


from sys import stdin, stdout
LEVEL_COUNT = 20

def get_preprocessed_input():
	n = int(stdin.readline())
	g = [[] for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, stdin.readline().split())
		u -= 1
		v -= 1
		g[u].append(v)
		g[v].append(u)
	d = [0] * n
	dp = [[0] * n for _ in range(LEVEL_COUNT)]
	p = dp[0]
	stack = [0]
	while stack:
		u = stack.pop()
		d[u] = d[p[u]] + 1
		for v in g[u]:
			if v != p[u]:
				p[v] = u
				stack.append(v)
	for level in range(1, LEVEL_COUNT):
		for i in range(n):
			dp[level][i] = dp[level - 1][dp[level - 1][i]]
	return (d, dp)

def lca(d, dp, a, b):
	if d[a] < d[b]:
		(a, b) = (b, a)
	for dp1 in reversed(dp):
		a1 = dp1[a]
		if d[a1] >= d[b]:
			a = a1
	if a == b:
		return a
	for dp1 in reversed(dp):
		a1 = dp1[a]
		b1 = dp1[b]
		if a1 != b1:
			a = a1
			b = b1
	return dp[0][a]

def path_len(d, dp, a, b):
	return d[a] + d[b] - 2 * d[lca(d, dp, a, b)]

def main():
	(d, dp) = get_preprocessed_input()
	for _ in range(int(stdin.readline())):
		(x, y, a, b, k) = map(int, stdin.readline().split())
		x -= 1
		y -= 1
		a -= 1
		b -= 1
		path1 = path_len(d, dp, a, b)
		path2 = min(path_len(d, dp, a, x) + path_len(d, dp, y, b), path_len(d, dp, a, y) + path_len(d, dp, x, b)) + 1
		if k >= path1 and k % 2 == path1 % 2 or (k >= path2 and k % 2 == path2 % 2):
			print('YES')
		else:
			print('NO')
main()


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List
from functools import lru_cache

def solve(N, edges, queries):
	LIM = 20
	parent = [[0 for _ in range(LIM)] for _ in range(N + 1)]
	depth = [0 for _ in range(N + 1)]

	def build(u, p):
		q = [(u, p)]
		while q:
			nq = []
			for (u, p) in q:
				depth[u] = depth[p] + 1
				parent[u][0] = p
				for i in range(1, LIM):
					parent[u][i] = parent[parent[u][i - 1]][i - 1]
				for v in edges[u]:
					if v != p:
						nq.append((v, u))
			q = nq

	def dist(x, y):
		if depth[x] > depth[y]:
			(x, y) = (y, x)
		d = 0
		for i in range(LIM - 1, -1, -1):
			if depth[parent[y][i]] >= depth[x]:
				y = parent[y][i]
				d += 1 << i
		if x == y:
			return d
		for i in range(LIM - 1, -1, -1):
			if parent[x][i] != parent[y][i]:
				x = parent[x][i]
				y = parent[y][i]
				d += 1 << i + 1
		return d + 2

	def checkparity(u, v):
		return u <= v and u % 2 == v % 2
	build(1, 0)
	ans = []
	for (x, y, a, b, k) in quries:
		dxy = 1 if x != y else 0
		d = dist(a, b)
		if checkparity(d, k):
			ans.append('YES')
			continue
		d = dist(a, x) + dist(y, b) + dxy
		if checkparity(d, k):
			ans.append('YES')
			continue
		d = dist(a, y) + dist(x, b) + dxy
		if checkparity(d, k):
			ans.append('YES')
			continue
		ans.append('NO')
	return '\n'.join(ans)
N = int(input())
edges = collections.defaultdict(list)
for i in range(N - 1):
	(u, v) = map(int, input().split())
	edges[u].append(v)
	edges[v].append(u)
M = int(input())
quries = []
for i in range(M):
	(x, y, a, b, k) = map(int, input().split())
	quries.append((x, y, a, b, k))
print(solve(N, edges, quries))


n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
logn = 19
st = [0] * n
dep = [-1] * n
par = [[0] * n for _ in range(logn + 1)]
(st[0], cur) = (0, 1)
dep[0] = 0
while cur > 0:
	x = st[cur - 1]
	cur = cur - 1
	for i in g[x]:
		if dep[i] is -1:
			dep[i] = 1 + dep[x]
			par[0][i] = x
			st[cur] = i
			cur = cur + 1
for i in range(1, logn + 1):
	for j in range(n):
		par[i][j] = par[i - 1][par[i - 1][j]]

def lca(i, j):
	if dep[i] > dep[j]:
		return lca(j, i)
	var = logn
	while var >= 0:
		if dep[j] - (1 << var) >= dep[i]:
			j = par[var][j]
		var = var - 1
	if i == j:
		return i
	var = logn
	while var >= 0:
		if par[var][i] is not par[var][j]:
			i = par[var][i]
			j = par[var][j]
		var = var - 1
	return par[0][i]

def dist(i, j):
	return dep[i] + dep[j] - 2 * dep[lca(i, j)]

def query(a, b, x, y, k):
	can = []
	can.append(dist(x, y))
	can.append(dist(x, a) + 1 + dist(b, y))
	can.append(dist(x, b) + 1 + dist(a, y))
	for i in can:
		if i % 2 == k % 2 and i <= k:
			return 'YES'
	return 'NO'
q = int(input())
for i in range(q):
	(x, y, a, b, k) = map(int, input().split())
	print(query(x - 1, y - 1, a - 1, b - 1, k))


import sys

class RangeMinQuery:

	def __init__(self, data):
		self._data = [list(data)]
		n = len(self._data[0])
		w = 1
		while 2 * w <= n:
			prev = self._data[-1]
			self._data.append([min(prev[j], prev[j + w]) for j in range(n - 2 * w + 1)])
			w *= 2

	def query(self, begin, end):
		assert begin < end
		depth = (end - begin).bit_length() - 1
		return min(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, graph, root=1):
		self.eulerTour = []
		self.preorder = [None] * len(graph)
		self.postorder = [None] * len(graph)
		self.depth = [None] * len(graph)
		self.parent = [None] * len(graph)
		stack = [root]
		self.depth[root] = 0
		self.parent[root] = None
		while stack:
			node = stack.pop()
			self.eulerTour.append(node)
			if self.preorder[node] is None:
				self.preorder[node] = len(self.eulerTour) - 1
				for nbr in graph[node]:
					if self.preorder[nbr] is None:
						self.depth[nbr] = self.depth[node] + 1
						self.parent[nbr] = node
						stack.append(node)
						stack.append(nbr)
			self.postorder[node] = len(self.eulerTour) - 1
		self.rmq = RangeMinQuery((self.preorder[node] for node in self.eulerTour))

	def lca(self, u, v):
		a = self.preorder[u]
		b = self.preorder[v]
		if a > b:
			(a, b) = (b, a)
		return self.eulerTour[self.rmq.query(a, b + 1)]

	def dist(self, u, v):
		return self.depth[u] + self.depth[v] - 2 * self.depth[self.lca(u, v)]

	def isAncestor(self, ancestor, v):
		return self.preorder[ancestor] <= self.preorder[v] and self.postorder[v] <= self.postorder[ancestor]

	def path(self, u, v):
		uPath = []
		while not self.isAncestor(u, v):
			uPath.append(u)
			u = self.parent[u]
		lca = u
		assert self.isAncestor(u, v)
		vPath = []
		while v != lca:
			vPath.append(v)
			v = self.parent[v]
		ret = uPath + [lca] + vPath[::-1]
		return ret

def solve(N, edges, queries):
	graph = [[] for i in range(N + 1)]
	for e in edges:
		graph[e[0]].append(e[1])
		graph[e[1]].append(e[0])
	tree = LCA(graph)
	ans = []
	for (x, y, a, b, k) in queries:
		d_ab = tree.dist(a, b)
		d_axyb = tree.dist(a, x) + 1 + tree.dist(y, b)
		d_ayxb = tree.dist(a, y) + 1 + tree.dist(x, b)
		if any((d <= k and (k - d) % 2 == 0 for d in [d_ab, d_axyb, d_ayxb])):
			ans.append('YES')
		else:
			ans.append('NO')
	return '\n'.join(ans)
input = sys.stdin.readline
N = int(input())
edges = []
for i in range(N - 1):
	edges.append(list(map(int, input().split())))
Q = int(input())
queries = []
for i in range(Q):
	queries.append(list(map(int, input().split())))
ans = solve(N, edges, queries)
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

@iterative
def dfs(v, visited, st, new, depth):
	new.append(st)
	visited[st] = 1
	for i in v[st]:
		if visited[i] == 0:
			depth[i] = depth[st] + 1
			ok = (yield dfs(v, visited, i, new, depth))
	yield True

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		depth = (end - begin).bit_length() - 1
		return self.func(self._data[depth][begin], self._data[depth][end - (1 << depth)])

class LCA:

	def __init__(self, root, graph):
		self.time = [-1] * len(graph)
		self.path = [-1] * len(graph)
		P = [-1] * len(graph)
		t = -1
		dfs = [root]
		while dfs:
			node = dfs.pop()
			self.path[t] = P[node]
			self.time[node] = t = t + 1
			for nei in graph[node]:
				if self.time[nei] == -1:
					P[nei] = node
					dfs.append(nei)
		self.rmq = RangeQuery((self.time[node] for node in self.path))

	def __call__(self, a, b):
		if a == b:
			return a
		a = self.time[a]
		b = self.time[b]
		if a > b:
			(a, b) = (b, a)
		return self.path[self.rmq.query(a, b)]

def dist(lca, depth, a, b):
	return depth[a] + depth[b] - 2 * depth[lca(a, b)]

def solve(case):
	n = int(inp())
	g = [[] for i in range(n)]
	for i in range(n - 1):
		(a, b) = sep()
		a -= 1
		b -= 1
		g[a].append(b)
		g[b].append(a)
	depth = [0] * n
	vis = [False] * n
	dfs(g, vis, 0, [], depth)
	lca = LCA(0, g)
	for i in range(int(inp())):
		(x, y, a, b, k) = sep()
		x -= 1
		y -= 1
		a -= 1
		b -= 1
		if k >= dist(lca, depth, a, b) and k % 2 == dist(lca, depth, a, b) % 2:
			print('YES')
			continue
		if k >= dist(lca, depth, a, x) + 1 + dist(lca, depth, y, b) and k % 2 == (dist(lca, depth, a, x) + 1 + dist(lca, depth, y, b)) % 2:
			print('YES')
			continue
		if k >= dist(lca, depth, a, y) + 1 + dist(lca, depth, x, b) and k % 2 == (dist(lca, depth, a, y) + 1 + dist(lca, depth, x, b)) % 2:
			print('YES')
			continue
		print('NO')
testcase(1)


import sys
inp = sys.stdin.buffer.readline

def input():
	return inp().strip()
out = []

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))
INF = 10 ** 5 + 7
n = iin()
adj = [[] for i in range(n + 1)]
for _ in range(n - 1):
	(i, j) = lin()
	adj[i].append(j)
	adj[j].append(i)

def dfs(adj, start=1):
	n = len(adj)
	visited = [False] * n
	first = [-1] * n
	euler = []
	height = [-1] * n
	srt = [start]
	height[start] = 1
	parent = [-1] * n
	while srt:
		v = srt.pop()
		if visited[v]:
			euler.append(v)
			continue
		first[v] = len(euler)
		euler.append(v)
		visited[v] = True
		if parent[v] != -1:
			srt.append(parent[v])
		for u in adj[v]:
			if not visited[u]:
				parent[u] = v
				height[u] = height[v] + 1
				srt.append(u)
	return (first, euler, height)
(first, euler, height) = dfs(adj)
euler = [height[i] for i in euler]

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, begin, end):
		end += 1
		depth = (end - begin).bit_length() - 1
		tmp = self._data[depth]
		return self.func(tmp[begin], tmp[end - (1 << depth)])
sa = RangeQuery(euler)

def check(i, j):
	(l, r) = (first[i], first[j])
	if l > r:
		(l, r) = (r, l)
	h = sa.query(l, r)
	return height[i] + height[j] - 2 * h
q = iin()
while q:
	q -= 1
	(x, y, a, b, k) = lin()
	ans1 = [check(a, b), check(a, x) + 1 + check(y, b), check(a, y) + 1 + check(x, b)]
	for i in ans1:
		if k - i >= 0 and (k - i) % 2 == 0:
			out.append('YES')
			break
	else:
		out.append('NO')
print('\n'.join(out))


import sys
n = int(input())
g = [[] for _ in range(n)]
t_in = [-1 for _ in range(n)]
t_out = [-1 for _ in range(n)]
height = [-1 for _ in range(n)]
time = 0
k = 0
while 2 ** k <= n:
	k += 1
up = [[0 for j in range(k + 1)] for i in range(n)]

def upper(a, b):
	return t_in[a] <= t_in[b] and t_out[a] >= t_out[b]

def lca(v, u):
	if height[v] > height[u]:
		(u, v) = (v, u)
	for i in reversed(range(k + 1)):
		if height[up[u][i]] - height[v] >= 0:
			u = up[u][i]
	if u == v:
		return u
	for i in reversed(range(k + 1)):
		if up[v][i] != up[u][i]:
			v = up[v][i]
			u = up[u][i]
	return up[v][0]

def dist(a, b):
	p = lca(a, b)
	result = height[a] - height[p] + (height[b] - height[p])
	return result

def dfs(v, p, depth):
	time = 0
	stack = [(v, p, depth)]
	while len(stack) > 0:
		x = stack.pop()
		if len(x) == 1:
			t_out[x[0]] = time
			time += 1
			continue
		(v, p, depth) = x
		t_in[v] = time
		time += 1
		height[v] = depth
		up[v][0] = p
		for i in range(1, k + 1):
			up[v][i] = up[up[v][i - 1]][i - 1]
		stack.append([v])
		for w in g[v]:
			if t_in[w] == -1:
				stack.append((w, v, depth + 1))

def check(dist, k):
	return dist <= k and dist % 2 == k % 2
for i in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)
dfs(0, 0, 0)
m = int(input())
for i in range(m):
	(x, y, a, b, q) = map(lambda x: int(x) - 1, input().split())
	q = q + 1
	dist1 = dist(a, b)
	if check(dist1, q):
		print('YES')
		continue
	dist2 = dist(a, x) + 1 + dist(y, b)
	if check(dist2, q):
		print('YES')
		continue
	dist3 = dist(a, y) + 1 + dist(b, x)
	if check(dist3, q):
		print('YES')
	else:
		print('NO')


def main():
	import sys
	input = sys.stdin.buffer.readline

	def STfunc(a, b):
		if a < b:
			return a
		else:
			return b

	class SparseTable:

		def __init__(self, A):
			self.N = len(A)
			self.K = self.N.bit_length() - 1
			self.table = [[0] * (self.K + 1) for _ in range(self.N)]
			for (i, a) in enumerate(A):
				self.table[i][0] = A[i]
			for k in range(1, self.K + 1):
				for i in range(self.N):
					j = i + (1 << k - 1)
					if j <= self.N - 1:
						self.table[i][k] = STfunc(self.table[i][k - 1], self.table[j][k - 1])
					else:
						self.table[i][k] = self.table[i][k - 1]

		def query(self, l, r):
			k = (r - l).bit_length() - 1
			return STfunc(self.table[l][k], self.table[r - (1 << k)][k])

	def EulerTour(adj, root):
		st = [root]
		ret = []
		seen = [0] * len(adj)
		par = [0] * len(adj)
		depth = [0] * len(adj)
		while st:
			v = st.pop()
			if seen[v]:
				ret.append(v)
				continue
			ret.append(v)
			seen[v] = 1
			if par[v] != 0:
				st.append(par[v])
			for u in adj[v]:
				if seen[u] == 0:
					st.append(u)
					par[u] = v
					depth[u] = depth[v] + 1
		return (ret, depth)
	N = int(input())
	adj = [[] for _ in range(N + 1)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		adj[a].append(b)
		adj[b].append(a)
	(et, depth) = EulerTour(adj, 1)
	depth_list = [0] * len(et)
	left = [-1] * (N + 1)
	right = [-1] * (N + 1)
	for (i, v) in enumerate(et):
		depth_list[i] = depth[v]
		if left[v] < 0:
			left[v] = i
		right[v] = i
	ST = SparseTable(depth_list)
	q = int(input())
	for i in range(q):
		(x, y, a, b, k) = map(int, input().split())
		lca_depth_AB = ST.query(min(left[a], left[b]), max(right[a], right[b]) + 1)
		AB = depth[a] + depth[b] - 2 * lca_depth_AB
		if k >= AB and (k - AB) % 2 == 0:
			print('YES')
			continue
		lca_depth_AX = ST.query(min(left[a], left[x]), max(right[a], right[x]) + 1)
		AX = depth[a] + depth[x] - 2 * lca_depth_AX
		lca_depth_BY = ST.query(min(left[b], left[y]), max(right[b], right[y]) + 1)
		BY = depth[b] + depth[y] - 2 * lca_depth_BY
		AB_new = AX + BY + 1
		if k >= AB_new and (k - AB_new) % 2 == 0:
			print('YES')
			continue
		lca_depth_AY = ST.query(min(left[a], left[y]), max(right[a], right[y]) + 1)
		AY = depth[a] + depth[y] - 2 * lca_depth_AY
		lca_depth_BX = ST.query(min(left[b], left[x]), max(right[b], right[x]) + 1)
		BX = depth[b] + depth[x] - 2 * lca_depth_BX
		AB_new = AY + BX + 1
		if k >= AB_new and (k - AB_new) % 2 == 0:
			print('YES')
			continue
		print('NO')
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial, log2, floor
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	n = N()
	gp = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(f, t) = RL()
		gp[f].append(t)
		gp[t].append(f)
	mxd = 100
	marr = [[0] * (mxd + 1) for _ in range(n + 1)]
	par = [1] * (n + 1)
	deep = [0] * (n + 1)
	vis = [0] * (n + 1)
	q = deque()
	q.append((1, 0))
	vis[1] = 1
	while q:
		(nd, d) = q.popleft()
		deep[nd] = d
		marr[nd][0] = par[nd]
		for i in range(1, mxd + 1):
			if 2 ** i > d:
				break
			marr[nd][i] = marr[marr[nd][i - 1]][i - 1]
		for nex in gp[nd]:
			if vis[nex] == 1:
				continue
			vis[nex] = 1
			par[nex] = nd
			q.append((nex, d + 1))

	def lca(a, b):
		(ta, tb) = (a, b)
		if deep[a] > deep[b]:
			(a, b) = (b, a)
		for i in range(mxd, -1, -1):
			if marr[b][i] != -1 and deep[marr[b][i]] >= deep[a]:
				b = marr[b][i]
		if a == b:
			return deep[ta] - deep[a] + deep[tb] - deep[a]
		for i in range(mxd, -1, -1):
			if marr[b][i] != marr[a][i]:
				a = marr[a][i]
				b = marr[b][i]
		ld = par[a] if a != b else a
		return deep[ta] - deep[ld] + deep[tb] - deep[ld]
	qn = N()
	for _ in range(qn):
		(x, y, a, b, k) = RL()
		lst = k & 1
		dis = lca(a, b)
		disaxyb = lca(a, x) + lca(y, b) + 1
		disayxb = lca(a, y) + lca(x, b) + 1
		if dis <= k and dis & 1 == lst or (disaxyb <= k and disaxyb & 1 == lst) or (disayxb <= k and disayxb & 1 == lst):
			print('YES')
		else:
			print('NO')
main()


from collections import deque
import sys
input = sys.stdin.readline

class LowestCommonAncestor:

	def __init__(self, tree, root):
		self.n = len(tree)
		self.depth = [0] * self.n
		self.log_size = self.n.bit_length()
		self.parent = [[-1] * self.n for i in range(self.log_size)]
		q = deque([(root, -1, 0)])
		while q:
			(v, par, dist) = q.pop()
			self.parent[0][v] = par
			self.depth[v] = dist
			for child_v in tree[v]:
				if child_v != par:
					self.depth[child_v] = dist + 1
					q.append((child_v, v, dist + 1))
		for k in range(1, self.log_size):
			for v in range(self.n):
				self.parent[k][v] = self.parent[k - 1][self.parent[k - 1][v]]

	def lca(self, u, v):
		if self.depth[u] > self.depth[v]:
			(u, v) = (v, u)
		for k in range(self.log_size):
			if self.depth[v] - self.depth[u] >> k & 1:
				v = self.parent[k][v]
		if u == v:
			return u
		for k in reversed(range(self.log_size)):
			if self.parent[k][u] != self.parent[k][v]:
				u = self.parent[k][u]
				v = self.parent[k][v]
		return self.parent[0][u]
n = int(input())
info = [list(map(int, input().split())) for i in range(n - 1)]
tree = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = info[i]
	a -= 1
	b -= 1
	tree[a].append(b)
	tree[b].append(a)
lca = LowestCommonAncestor(tree, 0)
q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
	(x, y, a, b, k) = query[i]
	lca_ab = lca.lca(a - 1, b - 1)
	ab = lca.depth[a - 1] + lca.depth[b - 1] - 2 * lca.depth[lca_ab]
	lca_xy = lca.lca(x - 1, y - 1)
	xy = lca.depth[x - 1] + lca.depth[y - 1] - 2 * lca.depth[lca_xy]
	lca_ax = lca.lca(a - 1, x - 1)
	lca_ay = lca.lca(a - 1, y - 1)
	lca_bx = lca.lca(b - 1, x - 1)
	lca_by = lca.lca(b - 1, y - 1)
	ax = lca.depth[a - 1] + lca.depth[x - 1] - 2 * lca.depth[lca_ax]
	ay = lca.depth[a - 1] + lca.depth[y - 1] - 2 * lca.depth[lca_ay]
	bx = lca.depth[b - 1] + lca.depth[x - 1] - 2 * lca.depth[lca_bx]
	by = lca.depth[b - 1] + lca.depth[y - 1] - 2 * lca.depth[lca_by]
	if ab <= k and k % 2 == ab % 2:
		print('YES')
	elif ax + 1 + by <= k and k % 2 == (ax + 1 + by) % 2:
		print('YES')
	elif ay + 1 + bx <= k and k % 2 == (ay + 1 + bx) % 2:
		print('YES')
	else:
		print('NO')


import sys, os
inp = [int(x) for x in sys.stdin.buffer.read().split()]
ii = 0
out = []
INF = 10 ** 5 + 7
n = inp[ii]
ii += 1
adj = [[] for i in range(n + 1)]
for _ in range(n - 1):
	(i, j) = (inp[ii], inp[ii + 1])
	ii += 2
	adj[i].append(j)
	adj[j].append(i)

def dfs(adj, start=1):
	n = len(adj)
	visited = [0] * n
	first = [-1] * n
	euler = []
	height = [-1] * n
	srt = [start]
	height[start] = 1
	parent = [-1] * n
	while srt:
		v = srt.pop()
		if visited[v]:
			euler.append(v)
			continue
		first[v] = len(euler)
		euler.append(v)
		visited[v] = 1
		if parent[v] != -1:
			srt.append(parent[v])
		for u in adj[v]:
			if not visited[u]:
				parent[u] = v
				height[u] = height[v] + 1
				srt.append(u)
	return (first, euler, height)
(first, euler, height) = dfs(adj)
euler = [height[i] for i in euler]

class Sparse_Table:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr)
		self.logfn = lambda x: x.bit_length() - 1
		self.table = self.build()

	def build(self):
		n = self.n
		sz = int(self.logfn(n)) + 1
		st = [[INF for i in range(n)] for j in range(sz)]
		st[0] = list(self.arr)
		for i in range(1, sz):
			step = 1 << i - 1
			sti = st[i]
			stim1 = st[i - 1]
			for j in range(n - step * 2 + 1):
				sti[j] = min(stim1[j + step], stim1[j])
		return st

	def query(self, begin, end):
		end += 1
		depth = (end - begin).bit_length() - 1
		return min(self.table[depth][begin], self.table[depth][end - (1 << depth)])
sa = Sparse_Table(euler)

def check(i, j):
	(l, r) = (first[i], first[j])
	if l > r:
		(l, r) = (r, l)
	h = sa.query(l, r)
	return height[i] + height[j] - 2 * h
q = inp[ii]
ii += 1
while q:
	q -= 1
	(x, y, a, b, k) = inp[ii:ii + 5]
	ii += 5
	ans1 = [check(a, b), check(a, x) + 1 + check(y, b), check(a, y) + 1 + check(x, b)]
	for i in ans1:
		if k - i >= 0 and (k - i) % 2 == 0:
			out.append(b'YES')
			break
	else:
		out.append(b'NO')
os.write(1, b'\n'.join(out))


class Stree:

	def __init__(self, f, n, default, init_data):
		self.ln = 2 ** (n - 1).bit_length()
		self.data = [default] * (self.ln * 2)
		self.f = f
		for (i, d) in init_data.items():
			self.data[self.ln + i] = d
		for j in range(self.ln - 1, -1, -1):
			self.data[j] = f(self.data[j * 2], self.data[j * 2 + 1])

	def update(self, i, a):
		p = self.ln + i
		self.data[p] = a
		while p > 1:
			p = p // 2
			self.data[p] = self.f(self.data[p * 2], self.data[p * 2 + 1])

	def get(self, i, j):

		def _get(l, r, p):
			if i <= l and j >= r:
				return self.data[p]
			else:
				m = (l + r) // 2
				if j <= m:
					return _get(l, m, p * 2)
				elif i >= m:
					return _get(m, r, p * 2 + 1)
				else:
					return self.f(_get(l, m, p * 2), _get(m, r, p * 2 + 1))
		return _get(0, self.ln, 1)

def dfs(adj):
	n = len(adj)
	parent = [None] * n
	depth = [-1] * n
	depth[0] = 0
	stack = [(0, adj[0])]
	euler = []
	eulerfirst = [-1] * n
	while stack:
		(p, aa) = stack.pop()
		if eulerfirst[p] == -1:
			eulerfirst[p] = len(euler)
		euler.append(p)
		for c in aa[::-1]:
			if c != parent[p]:
				parent[c] = p
				depth[c] = depth[p] + 1
				stack.append((p, []))
				stack.append((c, adj[c]))
	return (euler, eulerfirst, parent, depth)

class Lca:

	def __init__(self, adj):
		self.adj = adj
		(self.euler, self.eulerfirst, self.parent, self.depth) = dfs(adj)

		def f(l, r):
			if self.depth[l] < self.depth[r]:
				return l
			else:
				return r
		self.stree = Stree(f, len(self.euler), 0, dict(enumerate(self.euler)))

	def lca(self, a, b):
		if a == b:
			return a
		fa = self.eulerfirst[a]
		fb = self.eulerfirst[b]
		if fb < fa:
			(fa, fb) = (fb, fa)
		return self.stree.get(fa, fb)

	def dist(self, a, b):
		return self.depth[a] + self.depth[b] - 2 * self.depth[self.lca(a, b)]
from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():
	n = int(input())
	adj = [[] for _ in range(n)]
	for _ in range(n - 1):
		(x, y) = map(int, input().split())
		adj[x - 1].append(y - 1)
		adj[y - 1].append(x - 1)
	lca = Lca(adj)

	def solve():
		(x, y, a, b, k) = map(int, input().split())
		x -= 1
		y -= 1
		a -= 1
		b -= 1
		dab = lca.dist(a, b)
		if dab <= k and (k - dab) % 2 == 0:
			print('YES')
			return
		dxa = lca.dist(x, a)
		dyb = lca.dist(y, b)
		if dxa + dyb + 1 <= k and (k - dxa - dyb - 1) % 2 == 0:
			print('YES')
			return
		dya = lca.dist(y, a)
		dxb = lca.dist(x, b)
		if dya + dxb + 1 <= k and (k - dya - dxb - 1) % 2 == 0:
			print('YES')
			return
		print('NO')
	q = int(input())
	for _ in range(q):
		solve()
main()


from collections import deque
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
input = lambda : sys.stdin.readline().rstrip()
sys.stdout = BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(v, to) = map(int, input().split())
	v -= 1
	to -= 1
	g[v].append(to)
	g[to].append(v)
root = 0
visited = [False] * n
cs = [[] for _ in range(n)]
queue = deque([root])
while queue:
	v = queue.popleft()
	if not visited[v]:
		visited[v] = True
		for to in g[v]:
			cs[v].append(to)
			queue.append(to)
visited = [False] * n
stack = [(0, root)]
traversal = []
enters = [-1] * n
while stack:
	(depth, v) = stack.pop()
	if not visited[v]:
		visited[v] = True
		enters[v] = len(traversal)
		for child in cs[v]:
			stack.append((depth, v))
			stack.append((depth + 1, child))
	traversal.append((depth, v))
N = len(traversal)
k = 1
while 1 << k < N:
	k += 1
ST = [[float('inf')] * k for _ in range(N)]
for i in range(N):
	ST[i][0] = traversal[i]
for j in range(1, k):
	for i in range(N):
		if i + (1 << j) > N:
			continue
		ST[i][j] = min(ST[i][j - 1], ST[i + (1 << j - 1)][j - 1])
log_len = [0] * (N + 1)
for i in range(2, N + 1):
	log_len[i] = log_len[i >> 1] + 1
q = int(input())
for _ in range(q):
	(x, y, a, b, k) = map(int, input().split())
	x -= 1
	y -= 1
	a -= 1
	b -= 1
	Ia = enters[a]
	Ib = enters[b]
	(da, _) = traversal[Ia]
	(db, _) = traversal[Ib]
	L = min(Ia, Ib)
	R = max(Ia, Ib)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	curr = da - depth + db - depth
	if curr <= k and (k - curr) % 2 == 0:
		sys.stdout.write('YES'.encode() + b'\n')
		continue
	Ix = enters[x]
	Iy = enters[y]
	(dx, _) = traversal[Ix]
	(dy, _) = traversal[Iy]
	L = min(Ia, Ix)
	R = max(Ia, Ix)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	part_ax = da - depth + dx - depth
	L = min(Ib, Iy)
	R = max(Ib, Iy)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	part_by = db - depth + dy - depth
	curr = part_ax + 1 + part_by
	if curr <= k and (k - curr) % 2 == 0:
		sys.stdout.write('YES'.encode() + b'\n')
		continue
	L = min(Ia, Iy)
	R = max(Ia, Iy)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	part_ay = da - depth + dy - depth
	L = min(Ib, Ix)
	R = max(Ib, Ix)
	j = log_len[R - L + 1]
	(depth, lca) = min(ST[L][j], ST[R - (1 << j) + 1][j])
	part_bx = db - depth + dx - depth
	curr = part_ay + 1 + part_bx
	if curr <= k and (k - curr) % 2 == 0:
		sys.stdout.write('YES'.encode() + b'\n')
		continue
	sys.stdout.write('NO'.encode() + b'\n')


import sys
x = 150000
sys.setrecursionlimit(x)

def go():
	n = int(input())
	e = {i: set() for i in range(n)}
	for i in range(n - 1):
		(a, b) = map(lambda s: int(s) - 1, input().split())
		e[a].add(b)
		e[b].add(a)
	parent = [-1 for v in range(n)]
	lev = [-1 for v in range(n)]
	stack = [0]
	lev[0] = 0
	parent[0] = 0
	while stack:
		v = stack.pop()
		for u in e[v]:
			if parent[u] == -1:
				lev[u] = lev[v] + 1
				parent[u] = v
				stack.append(u)
	levmx = max(lev)
	bindep = levmx.bit_length()
	P = [[-1] * bindep for _ in range(n)]
	for i in range(n):
		P[i][0] = parent[i]
	for j in range(1, bindep):
		for i in range(n):
			if P[i][j - 1] != -1:
				P[i][j] = P[P[i][j - 1]][j - 1]

	def lca(u, v):
		if lev[u] < lev[v]:
			(u, v) = (v, u)
		dist = lev[u] - lev[v]
		while dist:
			podn = dist.bit_length() - 1
			u = P[u][podn]
			dist -= 1 << podn
		if u == v:
			return u
		j = bindep - 1
		while j >= 0:
			if P[u][j] != -1 and P[u][j] != P[v][j]:
				u = P[u][j]
				v = P[v][j]
			j -= 1
		return parent[u]

	def dist(a, b):
		return lev[a] + lev[b] - 2 * lev[lca(a, b)]
	ans = []
	Q = int(input())
	for _ in range(Q):
		(x, y, a, b, k) = map(int, input().split())
		(x, y, a, b) = map(lambda aa: aa - 1, [x, y, a, b])
		dab = dist(a, b)
		if dab <= k and (dab - k) % 2 == 0:
			ans.append('YES')
		else:
			dax = dist(a, x)
			dby = dist(b, y)
			if dax + 1 + dby <= k and (k - (dax + 1 + dby)) % 2 == 0:
				ans.append('YES')
			else:
				day = dist(a, y)
				dbx = dist(b, x)
				if dbx + 1 + day <= k and (k - (dbx + 1 + day)) % 2 == 0:
					ans.append('YES')
				else:
					ans.append('NO')
	print('\n'.join(ans))
go()


from sys import stdin, stdout
import math
graph = []
lca = []
depth = []
lim = 0

def build_lca(cur, p):
	global lca
	global depth
	global lim
	global graph
	stack = []
	stack.append((cur, p))
	while stack:
		(cur, p) = stack.pop()
		lca[cur][0] = p
		depth[cur] = depth[p] + 1
		for i in range(1, lim):
			lca[cur][i] = lca[lca[cur][i - 1]][i - 1]
		for i in graph[cur]:
			if i == p:
				continue
			stack.append((i, cur))

def get_lca(a, b):
	global lim
	global graph
	global lca
	global depth
	lg = 0
	if depth[a] > depth[b]:
		(a, b) = (b, a)
	for i in range(lim, -1, -1):
		if depth[lca[b][i]] >= depth[a]:
			b = lca[b][i]
			lg += int(pow(2, i))
	if b == a:
		return lg
	for i in range(lim, -1, -1):
		if lca[b][i] != lca[a][i]:
			b = lca[b][i]
			a = lca[a][i]
			lg += int(pow(2, i + 1))
	return lg + 2

def main():
	global graph
	global lca
	global depth
	global lim
	n = int(stdin.readline())
	lim = int(math.log(n, 2)) + 1
	graph = [set() for _ in range(n + 1)]
	lca = [[0 for _ in range(lim + 1)] for _ in range(n + 1)]
	depth = [0 for _ in range(n + 1)]
	for _ in range(n - 1):
		(a, b) = list(map(int, stdin.readline().split()))
		graph[a].add(b)
		graph[b].add(a)
	build_lca(1, 0)
	q = int(stdin.readline())
	for _ in range(q):
		(x, y, a, b, k) = list(map(int, stdin.readline().split()))
		ans = -1
		temp = get_lca(a, b)
		if temp % 2 == k % 2 and k >= temp:
			stdout.write('YES\n')
			continue
		temp = min(get_lca(x, a) + get_lca(y, b), get_lca(x, b) + get_lca(y, a)) + 1
		if temp % 2 == k % 2 and k >= temp:
			stdout.write('YES\n')
			continue
		stdout.write('NO\n')
main()


from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def main():
	n = int(input())
	adj = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(u, v) = readIntArr()
		adj[u].append(v)
		adj[v].append(u)

	@bootstrap
	def dfsPopulateAncestor(node, d):
		m = len(path)
		b = 1
		while m - b >= 0:
			nodeAncestors[node].append(path[m - b])
			b *= 2
		nodeDepths[node] = d
		path.append(node)
		for nex in adj[node]:
			if len(path) >= 2 and nex == path[-2]:
				continue
			yield dfsPopulateAncestor(nex, d + 1)
		path.pop()
		yield None
	nodeDepths = [None for _ in range(n + 1)]
	nodeAncestors = [[] for _ in range(n + 1)]
	root = 1
	path = []
	dfsPopulateAncestor(root, 0)

	@bootstrap
	def dfsEulerTour(node, p):
		startTimes[node] = time[0]
		time[0] += 1
		for nex in adj[node]:
			if nex == p:
				continue
			yield dfsEulerTour(nex, node)
		endTimes[node] = time[0]
		time[0] += 1
		yield None
	startTimes = [0 for _ in range(n + 1)]
	endTimes = [0 for _ in range(n + 1)]
	time = [0]
	dfsEulerTour(root, -1)

	def isAncestor(node, ancestorCandidate):
		ac = ancestorCandidate
		return startTimes[ac] <= startTimes[node] and endTimes[ac] >= endTimes[node]

	def getLCA(u, v):
		if isAncestor(u, v):
			return v
		elif isAncestor(v, u):
			return u
		else:
			ancestor = u
			while True:
				ancs = nodeAncestors[ancestor]
				m = len(ancs)
				assert m > 0
				if isAncestor(v, ancs[0]):
					LCA = ancs[0]
					break
				broken = False
				for i in range(m):
					if isAncestor(v, ancs[i]):
						ancestor = ancs[i - 1]
						broken = True
						break
				if broken == False:
					ancestor = ancs[-1]
			return LCA

	def getDist(u, v):
		LCA = getLCA(u, v)
		return nodeDepths[u] + nodeDepths[v] - 2 * nodeDepths[LCA]
	q = int(input())
	allans = []
	for _ in range(q):
		(x, y, a, b, k) = readIntArr()
		ans = 'NO'
		temp = k - getDist(a, b)
		if temp >= 0 and temp % 2 == 0:
			ans = 'YES'
		xy = getDist(x, y)
		temp = k - (getDist(a, x) + getDist(b, y) + 1)
		if temp >= 0 and temp % 2 == 0:
			ans = 'YES'
		temp = temp - (1 + xy)
		if temp >= 0 and temp % 2 == 0:
			ans = 'YES'
		temp = k - (getDist(a, y) + getDist(b, x) + 1)
		if temp >= 0 and temp % 2 == 0:
			ans = 'YES'
		temp = temp - (1 + xy)
		if temp >= 0 and temp % 2 == 0:
			ans = 'YES'
		allans.append(ans)
	multiLineArrayPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()