#include<bits/stdc++.h>
using namespace std;
#define ll  int
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
int vis[101][1001];
int a[101];
ll n;
bool exists(ll x,ll y){
if((x>=1)&&(x<=n)&&(y<=a[x]+1)&&(y>=1)) return 1;
return 0;
}
int main(){
reopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);
cin>>n;
for(int i=1;i<=n ;i++)
{
 cin>>a[i];
}
ll r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
queue<pi>q;
q.push(mp(r1,c1));
vis[r1][c1]=1;
pi it;
while(q.size()){
it=q.front();
q.pop();
if(it.f==r2&&it.s==c2) break;
if(exists(it.f,it.s-1)&&!vis[it.f][it.s-1]){
  vis[it.f][it.s-1]=vis[it.f][it.s]+1;
  q.push(mp(it.f,it.s-1));
}
if(exists(it.f,it.s+1)&&!vis[it.f][it.s+1]){
  vis[it.f][it.s+1]=vis[it.f][it.s]+1;
  q.push(mp(it.f,it.s+1));
}
if(it.f>1){
  if(exists(it.f-1,it.s)&&a[it.f-1]+1>=it.s&&!vis[it.f-1][it.s]){
    q.push(mp(it.f-1,it.s));
    vis[it.f-1][it.s]=1+vis[it.f][it.s];
  }
  else if(!vis[it.f-1][a[it.f-1]+1]&&exists(it.f-1,a[it.f-1]+1)){
    q.push(mp(it.f-1,a[it.f-1]+1));
    vis[it.f-1][a[it.f-1]+1]=1+vis[it.f][it.s];
  }
}
if(it.f<n){
if(a[it.f+1]+1>=it.s&&!vis[it.f+1][it.s]&&exists(it.f+1,it.s)){
    q.push(mp(it.f+1,it.s));
    vis[it.f+1][it.s]=1+vis[it.f][it.s];
  }
  else if(!vis[it.f+1][a[it.f+1]+1]&&exists(it.f+1,a[it.f+1]+1)){
    q.push(mp(it.f+1,a[it.f+1]+1));
    vis[it.f+1][a[it.f+1]+1]=1+vis[it.f][it.s];
  }
}
}
cout<<vis[r2][c2]-1;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  int
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
map<pi,int>vis;
int a[101];
ll n;
bool exists(ll x,ll y){
if((x>=1)&&(x<=n)&&(y<=a[x]+1)&&(y>=1)) return 1;
return 0;
}
int main(){
    freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);
cin>>n;
for(int i=1;i<=n;i++){
 cin>>a[i];
}
ll r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
queue<pi>q;
q.push(mp(r1,c1));
vis[mp(r1,c1)]=1;
pi it;
while(q.size()){
it=q.front();
q.pop();
if(it.f==r2&&it.s==c2) break;
if((it.s-1>0)&&!vis[mp(it.f,it.s-1)]){
  vis[mp(it.f,it.s-1)]=vis[mp(it.f,it.s)]+1;
  q.push(mp(it.f,it.s-1));
}
if((it.s+1<=a[it.f]+1)&&!vis[mp(it.f,it.s+1)]){
  vis[mp(it.f,it.s+1)]=vis[mp(it.f,it.s)]+1;
  q.push(mp(it.f,it.s+1));
}
if(it.f>1){
  if(a[it.f-1]+1>=it.s&&!vis[mp(it.f-1,it.s)]){
    q.push(mp(it.f-1,it.s));
    vis[mp(it.f-1,it.s)]=1+vis[mp(it.f,it.s)];
  }
  else if(!vis[mp(it.f-1,a[it.f-1]+1)]){
    q.push(mp(it.f-1,a[it.f-1]+1));
    vis[mp(it.f-1,a[it.f-1]+1)]=1+vis[mp(it.f,it.s)];
  }
}
if(it.f<n){
if(a[it.f+1]+1>=it.s&&!vis[mp(it.f+1,it.s)]){
    q.push(mp(it.f+1,it.s));
    vis[mp(it.f+1,it.s)]=1+vis[mp(it.f,it.s)];
  }
  else if(!vis[mp(it.f+1,a[it.f+1]+1)]){
    q.push(mp(it.f+1,a[it.f+1]+1));
    vis[mp(it.f+1,a[it.f+1]+1)]=1+vis[mp(it.f,it.s)];
  }
}
}
cout<<vis[mp(r2,c2)]-1;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll vis[101][100001];
ll a[101];
ll n;
bool exists(ll x,ll y){
if(x>=1&&x<=n&&(y<=a[x]+1)&&y>=1) return 1;
return 0;
}
int main(){
cin>>n;
for(int i=1;i<=n ;i++)
{
 cin>>a[i];
}
ll r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
queue<pi>q;
q.push(mp(r1,c1));
vis[r1][c1]=1;
pi it;
while(q.size()){
it=q.front();
q.pop();
if(it.f==r2&&it.s==c2) break;
if(exists(it.f,it.s-1)&&!vis[it.f][it.s-1]){
  vis[it.f][it.s-1]=vis[it.f][it.s]+1;
  q.push(mp(it.f,it.s-1));
}
if(exists(it.f,it.s+1)&&!vis[it.f][it.s+1]){
  vis[it.f][it.s+1]=vis[it.f][it.s]+1;
  q.push(mp(it.f,it.s+1));
}
if(it.f>1){
  if(a[it.f-1]+1>=it.s&&!vis[it.f-1][it.s]){
    q.push(mp(it.f-1,it.s));
    vis[it.f-1][it.s]=1+vis[it.f][it.s];
  }
  else if(!vis[it.f-1][a[it.f-1]+1]){
    q.push(mp(it.f-1,a[it.f-1]+1));
    vis[it.f-1][a[it.f-1]+1]=1+vis[it.f][it.s];
  }
}
if(it.f<n){
if(a[it.f+1]+1>=it.s&&!vis[it.f+1][it.s]){
    q.push(mp(it.f+1,it.s));
    vis[it.f+1][it.s]=1+vis[it.f][it.s];
  }
  else if(!vis[it.f+1][a[it.f+1]+1]){
    q.push(mp(it.f+1,a[it.f+1]+1));
    vis[it.f+1][a[it.f+1]+1]=1+vis[it.f][it.s];
  }
}
}
cout<<vis[r2][c2]-1;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll vis[101][100001];
ll a[101];
ll n;
bool exists(ll x,ll y){
if(x>=1&&x<=n&&(y<=a[x]+1)&&y>=1) return 1;
return 0;
}
int main(){
     freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);
cin>>n;
for(int i=1;i<=n ;i++)
{
 cin>>a[i];
}
ll r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
queue<pi>q;
q.push(mp(r1,c1));
vis[r1][c1]=1;
pi it;
while(q.size()){
it=q.front();
q.pop();
if(it.f==r2&&it.s==c2) break;
if(exists(it.f,it.s-1)&&!vis[it.f][it.s-1]){
  vis[it.f][it.s-1]=vis[it.f][it.s]+1;
  q.push(mp(it.f,it.s-1));
}
if(exists(it.f,it.s+1)&&!vis[it.f][it.s+1]){
  vis[it.f][it.s+1]=vis[it.f][it.s]+1;
  q.push(mp(it.f,it.s+1));
}
if(it.f>1){
  if(a[it.f-1]+1>=it.s&&!vis[it.f-1][it.s]){
    q.push(mp(it.f-1,it.s));
    vis[it.f-1][it.s]=1+vis[it.f][it.s];
  }
  else if(!vis[it.f-1][a[it.f-1]+1]){
    q.push(mp(it.f-1,a[it.f-1]+1));
    vis[it.f-1][a[it.f-1]+1]=1+vis[it.f][it.s];
  }
}
if(it.f<n){
if(a[it.f+1]+1>=it.s&&!vis[it.f+1][it.s]){
    q.push(mp(it.f+1,it.s));
    vis[it.f+1][it.s]=1+vis[it.f][it.s];
  }
  else if(!vis[it.f+1][a[it.f+1]+1]){
    q.push(mp(it.f+1,a[it.f+1]+1));
    vis[it.f+1][a[it.f+1]+1]=1+vis[it.f][it.s];
  }
}
}
cout<<vis[r2][c2]-1;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  int
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
map<pi,int>vis;
int a[101];
ll n;
bool exists(ll x,ll y){
if((x>=1)&&(x<=n)&&(y<=a[x]+1)&&(y>=1)) return 1;
return 0;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
 cin>>a[i];
}
ll r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
queue<pi>q;
q.push(mp(r1,c1));
vis[mp(r1,c1)]=1;
pi it;
while(q.size()){
it=q.front();
q.pop();
if(it.f==r2&&it.s==c2) break;
if(exists(it.f,it.s-1)&&!vis[mp(it.f,it.s-1)]){
  vis[mp(it.f,it.s-1)]=vis[mp(it.f,it.s)]+1;
  q.push(mp(it.f,it.s-1));
}
if(exists(it.f,it.s+1)&&!vis[mp(it.f,it.s+1)]){
  vis[mp(it.f,it.s+1)]=vis[mp(it.f,it.s)]+1;
  q.push(mp(it.f,it.s+1));
}
if(it.f>1){
  if(exists(it.f-1,it.s)&&a[it.f-1]+1>=it.s&&!vis[mp(it.f-1,it.s)]){
    q.push(mp(it.f-1,it.s));
    vis[mp(it.f-1,it.s)]=1+vis[mp(it.f,it.s)];
  }
  else if(!vis[mp(it.f-1,a[it.f-1]+1)]&&exists(it.f-1,a[it.f-1]+1)){
    q.push(mp(it.f-1,a[it.f-1]+1));
    vis[mp(it.f-1,a[it.f-1]+1)]=1+vis[mp(it.f,it.s)];
  }
}
if(it.f<n){
if(a[it.f+1]+1>=it.s&&!vis[mp(it.f+1,it.s)]&&exists(it.f+1,it.s)){
    q.push(mp(it.f+1,it.s));
    vis[mp(it.f+1,it.s)]=1+vis[mp(it.f,it.s)];
  }
  else if(!vis[mp(it.f+1,a[it.f+1]+1)]&&exists(it.f+1,a[it.f+1]+1)){
    q.push(mp(it.f+1,a[it.f+1]+1));
    vis[mp(it.f+1,a[it.f+1]+1)]=1+vis[mp(it.f,it.s)];
  }
}
}
cout<<vis[mp(r2,c2)]-1;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  int
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
ll a[105+1];
void solve(ll r1,ll r2,ll &mi){
    ll d=1;
    if(r1>r2) d=-1;
while(r1!=r2){
    mi=min(mi,a[r1]);
    r1+=d;
    mi=min(mi,a[r1]);
}
}
int main(){
ll n;
freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
cin>>n;

for(int i=1;i<=n;i++) {cin>>a[i];
a[i]++;
}
ll r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
ll mi;
ll ans=INT_MAX;
for(int i=1;i<=n;i++){
mi=c1;
solve(r1,i,mi);
solve(r2,i,mi);
ans=min(ans,abs(i-r2)+abs(i-r1)+abs(mi-c2));
}
cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  int
#define pi pair<ll,ll>
#define f first
#define s second
#define mp make_pair
int vis[101][1001];
int a[101];
ll n;
bool exists(ll x,ll y){
if((x>=1)&&(x<=n)&&(y<=a[x]+1)&&(y>=1)) return 1;
return 0;
}
int main(){
cin>>n;
for(int i=1;i<=n ;i++)
{
 cin>>a[i];
}
ll r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
queue<pi>q;
q.push(mp(r1,c1));
vis[r1][c1]=1;
pi it;
while(q.size()){
it=q.front();
q.pop();
if(it.f==r2&&it.s==c2) break;
if(exists(it.f,it.s-1)&&!vis[it.f][it.s-1]){
  vis[it.f][it.s-1]=vis[it.f][it.s]+1;
  q.push(mp(it.f,it.s-1));
}
if(exists(it.f,it.s+1)&&!vis[it.f][it.s+1]){
  vis[it.f][it.s+1]=vis[it.f][it.s]+1;
  q.push(mp(it.f,it.s+1));
}
if(it.f>1){
  if(exists(it.f-1,it.s)&&a[it.f-1]+1>=it.s&&!vis[it.f-1][it.s]){
    q.push(mp(it.f-1,it.s));
    vis[it.f-1][it.s]=1+vis[it.f][it.s];
  }
  else if(!vis[it.f-1][a[it.f-1]+1]&&exists(it.f-1,a[it.f-1]+1)){
    q.push(mp(it.f-1,a[it.f-1]+1));
    vis[it.f-1][a[it.f-1]+1]=1+vis[it.f][it.s];
  }
}
if(it.f<n){
if(a[it.f+1]+1>=it.s&&!vis[it.f+1][it.s]&&exists(it.f+1,it.s)){
    q.push(mp(it.f+1,it.s));
    vis[it.f+1][it.s]=1+vis[it.f][it.s];
  }
  else if(!vis[it.f+1][a[it.f+1]+1]&&exists(it.f+1,a[it.f+1]+1)){
    q.push(mp(it.f+1,a[it.f+1]+1));
    vis[it.f+1][a[it.f+1]+1]=1+vis[it.f][it.s];
  }
}
}
cout<<vis[r2][c2]-1;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,r1,r2,c1,c2;;
int a[1000];
int dis(int x1,int y1,int x2,int y2) // (x1,y1) to (x2,y2)
{
    int d,sum = 0;
    if(x1 < x2) // x1 -> x2 down
    {
        d = y1;
        for(int i=x1+1; i<=x2; i++)
        {
            d = min(d,a[i]);
            sum++;
        }
        sum += abs(d-y2);
    }
    else
    {
        d = y1;
        for(int i=x1-1; i>=x2; i--)
        {
            d = min(d,a[i]);
            sum++;
        }
        sum += abs(d-y2);
    }
    return sum;
}
int main()
{
//     freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
    while(cin >> n)
    {
        for(int i=1; i<=n; i++)
        {
            cin >> a[i];
            a[i]++;
        }
        cin >> r1 >> c1 >> r2 >> c2;
        int ans = dis(r1,c1,r2,c2);
        if(c1 <= c2)
        {
            cout << ans << endl;continue;
        }
        for(int i=1; i<=n; i++)
        {
            int tmp1 = dis(r1,c1,i,c1>=a[i]?a[i]:c1);
            int tmp2 = dis(i,a[i],r2,c2);
            ans = min(ans,tmp1+tmp2);
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > matx(1000000);
vector<int> vert, d, dist(1000000), pos(1000000), len(1000000), le(1000000);
pair<int, int> table[1000000][50];
vector<bool> used(1000000);
int k;
void dfs(int v)
{
    used[v] = true;
    pos[v] = vert.size();
    vert.push_back(v);
    d.push_back(dist[v]);
    for (int i = 0; i < matx[v].size(); i++)
        if (!used[matx[v][i]])
        {
            dist[matx[v][i]] = dist[v]+1;
            dfs(matx[v][i]);
            vert.push_back(v);
            d.push_back(dist[v]);
        }
}
void build(int n)
{
    int o = 0, kk = 2;
    for (int i = 0; i < 18; i++)
        for (int j = 0; j < n; j++)
            table[i][j] = {0, 0};
    for (int i = 0; i < n; i++)
        table[0][i] = {d[i], vert[i]};
    while (kk < n)
    {
        o++;
        for (int i = kk-1; i < n; i++)
            if (table[o-1][i].first <  table[o-1][i-(kk / 2)].first)
                table[o][i] = table[o-1][i];
            else
                table[o][i] = table[o-1][i-(kk / 2)];
        kk *= 2;
    }
    int l = 1, m = 0;
    for (int i = 0; i < 17; i++)
    {
        for (int j = 0; j < l; j++)
        {
            m++;
            len[m] = i;
            le[m] = l;
        }
        l *= 2;
    }
    len[0] = -1;
}
int lca(int u, int v)
{
    if (u > v)
        swap(u, v);
    int l = (v-u+1);
    if (table[len[l]][v].first < table[len[l]][u+le[l]-1].first)
        return table[len[l]][v].second;
    else
        return table[len[l]][u+le[l]-1].second;
}
int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        matx[x].push_back(y);
        matx[y].push_back(x);
    }
    dist[0] = 0;
    dfs(0);
    build(vert.size());
    int q;
    cin >> q;
    for (int i1 = 0; i1 < q; i1++)
    {
        int x, y, a, b, k;
        cin >> x >> y >> a >> b >> k;
        x--;
        y--;
        a--;
        b--;
        bool flag1 = false, flag2 = false, flag3 = false;
        int ab = lca(pos[a], pos[b]), ax = lca(pos[a], pos[x]), ay = lca(pos[a], pos[y]), bx = lca(pos[b], pos[x]), by = lca(pos[b], pos[y]);
        int d1 = (dist[a]+dist[b]-2*dist[ab]);
        int d2 = (dist[a]+dist[x]-2*dist[ax]+dist[b]+dist[y]-2*dist[by]+1);
        int d3 = (dist[a]+dist[y]-2*dist[ay]+dist[b]+dist[x]-2*dist[bx]+1);
        if ((d1 % 2 == k % 2 && d1 <= k) || (d2 % 2 == k % 2 && d2 <= k) || (d3 % 2 == k % 2 && d3 <= k))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > matx(1000000);
vector<int> vert, d, dist(1000000), pos(1000000), len(1000000);
pair<int, int> table[1000000][50];
vector<bool> used(1000000);
int k;
void dfs(int v)
{
    used[v] = true;
    pos[v] = vert.size();
    vert.push_back(v);
    d.push_back(dist[v]);
    for (int i = 0; i < matx[v].size(); i++)
        if (!used[matx[v][i]])
        {
            dist[matx[v][i]] = dist[v]+1;
            dfs(matx[v][i]);
            vert.push_back(v);
            d.push_back(dist[v]);
        }
}
void build(int n)
{
    int kk = 2;
    int m = 1;
    for (int i = 0; i < n; i++)
        table[i][0] = {d[i], vert[i]};
    while (n >= kk)
    {
        for (int i = 0; i+kk <= n; i++)
            if (table[i][m-1].first < table[i+kk / 2][m-1].first)
                table[i][m] = table[i][m-1];
            else
                table[i][m] = table[i+kk / 2][m-1];
        kk *= 2;
        m++;
    }
    kk = 1;
    int p = 0;
    m = 1;
    while (kk <= n)
    {
        int k1 = kk;
        while (k1 > 0)
        {
            len[m] = p;
            m++;
            k1--;
        }
        kk *= 2;
        p++;
    }
    len[0] = -1;
}
int lca(int u, int v)
{
    if (u > v)
        swap(u, v);
    int l = (v-u+1);
    if (table[u][len[l]].first < table[v-len[l]][len[l]].first)
        return table[u][len[l]].second;
    else
        return table[v-len[l]][len[l]].second;
}
int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        matx[x].push_back(y);
        matx[y].push_back(x);
    }
    dist[0] = 0;
    dfs(0);
    build(vert.size());
    int q;
    cin >> q;
    for (int i1 = 0; i1 < q; i1++)
    {
        int x, y, a, b, k;
        cin >> x >> y >> a >> b >> k;
        x--;
        y--;
        a--;
        b--;
        bool flag1 = false, flag2 = false, flag3 = false;
        int ab = lca(pos[a], pos[b]), ax = lca(pos[a], pos[x]), ay = lca(pos[a], pos[y]), bx = lca(pos[b], pos[x]), by = lca(pos[b], pos[y]);
        int d1 = (dist[a]+dist[b]-2*dist[ab]);
        int d2 = (dist[a]+dist[x]-2*dist[ax]+dist[b]+dist[y]-2*dist[by]+1);
        int d3 = (dist[a]+dist[y]-2*dist[ay]+dist[b]+dist[x]-2*dist[bx]+1);
        if ((d1 % 2 == k % 2 && d1 <= k) || (d2 % 2 == k % 2 && d2 <= k) || (d3 % 2 == k % 2 && d3 <= k))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > matx(5000000);
vector<int> vert, d, dist(9000000), pos(9000000), len(9000000), le(9000000);
pair<int, int> table[2200000][30];
vector<bool> used(9000000);
int k;
void dfs(int v)
{
    used[v] = true;
    pos[v] = vert.size();
    vert.push_back(v);
    d.push_back(dist[v]);
    for (int i = 0; i < matx[v].size(); i++)
        if (!used[matx[v][i]])
        {
            dist[matx[v][i]] = dist[v]+1;
            dfs(matx[v][i]);
            vert.push_back(v);
            d.push_back(dist[v]);
        }
}
void build(int n)
{
    int o = 0, kk = 2;
    for (int i = 0; i < 30; i++)
        for (int j = 0; j < n; j++)
            table[i][j] = {0, 0};
    for (int i = 0; i < n; i++)
        table[0][i] = {d[i], vert[i]};
    while (kk < n)
    {
        o++;
        for (int i = kk-1; i < n; i++)
            if (table[o-1][i].first <  table[o-1][i-(kk / 2)].first)
                table[o][i] = table[o-1][i];
            else
                table[o][i] = table[o-1][i-(kk / 2)];
        kk *= 2;
    }
    int l = 1, m = 0;
    for (int i = 0; i < 20; i++)
    {
        for (int j = 0; j < l; j++)
        {
            m++;
            len[m] = i;
            le[m] = l;
        }
        l *= 2;
    }
    len[0] = -1;
}
int lca(int u, int v)
{
    if (u > v)
        swap(u, v);
    int l = (v-u+1);
    if (table[len[l]][v].first < table[len[l]][u+le[l]-1].first)
        return table[len[l]][v].second;
    else
        return table[len[l]][u+le[l]-1].second;
}
int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        matx[x].push_back(y);
        matx[y].push_back(x);
    }
    dist[0] = 0;
    dfs(0);
    build(vert.size());
    int q;
    cin >> q;
    for (int i1 = 0; i1 < q; i1++)
    {
        int x, y, a, b, k;
        cin >> x >> y >> a >> b >> k;
        x--;
        y--;
        a--;
        b--;
        bool flag1 = false, flag2 = false, flag3 = false;
        int ab = lca(pos[a], pos[b]), ax = lca(pos[a], pos[x]), ay = lca(pos[a], pos[y]), bx = lca(pos[b], pos[x]), by = lca(pos[b], pos[y]);
        int d1 = (dist[a]+dist[b]-2*dist[ab]);
        int d2 = (dist[a]+dist[x]-2*dist[ax]+dist[b]+dist[y]-2*dist[by]+1);
        int d3 = (dist[a]+dist[y]-2*dist[ay]+dist[b]+dist[x]-2*dist[bx]+1);
        if ((d1 % 2 == k % 2 && d1 <= k) || (d2 % 2 == k % 2 && d2 <= k) || (d3 % 2 == k % 2 && d3 <= k))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > matx(5000000);
vector<int> vert, d, dist(5000000), pos(5000000), len(5000000), le(5000000);
pair<int, int> table[2150000][21];
vector<bool> used(5000000);
int k;
void dfs(int v)
{
    used[v] = true;
    pos[v] = vert.size();
    vert.push_back(v);
    d.push_back(dist[v]);
    for (int i = 0; i < matx[v].size(); i++)
        if (!used[matx[v][i]])
        {
            dist[matx[v][i]] = dist[v]+1;
            dfs(matx[v][i]);
            vert.push_back(v);
            d.push_back(dist[v]);
        }
}
void build(int n)
{
    int o = 0, kk = 2;
    for (int i = 0; i < 21; i++)
        for (int j = 0; j < n; j++)
            table[i][j] = {0, 0};
    for (int i = 0; i < n; i++)
        table[0][i] = {d[i], vert[i]};
    while (kk < n)
    {
        o++;
        for (int i = kk-1; i < n; i++)
            if (table[o-1][i].first <  table[o-1][i-(kk / 2)].first)
                table[o][i] = table[o-1][i];
            else
                table[o][i] = table[o-1][i-(kk / 2)];
        kk *= 2;
    }
    int l = 1, m = 0;
    for (int i = 0; i < 20; i++)
    {
        for (int j = 0; j < l; j++)
        {
            m++;
            len[m] = i;
            le[m] = l;
        }
        l *= 2;
    }
    len[0] = -1;
}
int lca(int u, int v)
{
    if (u > v)
        swap(u, v);
    int l = (v-u+1);
    if (table[len[l]][v].first < table[len[l]][u+le[l]-1].first)
        return table[len[l]][v].second;
    else
        return table[len[l]][u+le[l]-1].second;
}
int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        matx[x].push_back(y);
        matx[y].push_back(x);
    }
    dist[0] = 0;
    dfs(0);
    build(vert.size());
    int q;
    cin >> q;
    for (int i1 = 0; i1 < q; i1++)
    {
        int x, y, a, b, k;
        cin >> x >> y >> a >> b >> k;
        x--;
        y--;
        a--;
        b--;
        bool flag1 = false, flag2 = false, flag3 = false;
        int ab = lca(pos[a], pos[b]), ax = lca(pos[a], pos[x]), ay = lca(pos[a], pos[y]), bx = lca(pos[b], pos[x]), by = lca(pos[b], pos[y]);
        int d1 = (dist[a]+dist[b]-2*dist[ab]);
        int d2 = (dist[a]+dist[x]-2*dist[ax]+dist[b]+dist[y]-2*dist[by]+1);
        int d3 = (dist[a]+dist[y]-2*dist[ay]+dist[b]+dist[x]-2*dist[bx]+1);
        if ((d1 % 2 == k % 2 && d1 <= k) || (d2 % 2 == k % 2 && d2 <= k) || (d3 % 2 == k % 2 && d3 <= k))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > matx(200000);
vector<int> vert, d, dist(200000), t(1200000), t1(1200000), pos(200000);
vector<bool> used(200000);
int k;
void dfs(int v)
{
    used[v] = true;
    pos[v] = vert.size();
    vert.push_back(v);
    d.push_back(dist[v]);
    for (int i = 0; i < matx[v].size(); i++)
        if (!used[matx[v][i]])
        {
            dist[matx[v][i]] = dist[v]+1;
            dfs(matx[v][i]);
            vert.push_back(v);
            d.push_back(dist[v]);
        }
}
void build(int l, int r, int v)
{
    if (l == r)
    {
        t1[v] = vert[l];
        t[v] = d[l];
    }
    else
    {
        build(l, (l+r) / 2, v*2+1);
        build((l+r) / 2+1, r, v*2+2);
        t[v] = min(t[v*2+1], t[v*2+2]);
        if (t[v*2+1] < t[v*2+2])
            t1[v] = t1[v*2+1];
        else
            t1[v] = t1[v*2+2];
    }
}
pair<int, int> find_min(int l, int r, int lx, int rx, int v)
{
    if (r < lx || l > rx)
        return {2000000000, 1};
    if (l >= lx && r <= rx)
        return {t[v], t1[v]};
    int k1 = find_min((l+r) / 2+1, r, lx, rx, v*2+2).second;
    if (find_min(l, (l+r) / 2, lx, rx, v*2+1).first < find_min((l+r) / 2+1, r, lx, rx, v*2+2).first)
        k1 = find_min(l, (l+r) / 2, lx, rx, v*2+1).second;
    int mn = min(find_min(l, (l+r) / 2, lx, rx, v*2+1).first, find_min((l+r) / 2+1, r, lx, rx, v*2+2).first);
    return {mn, k1};
}
int lca(int u, int v)
{
    if (u > v)
        swap(u, v);
    return find_min(0, k, u, v, 0).second;
}
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        matx[x].push_back(y);
        matx[y].push_back(x);
    }
    dist[0] = 0;
    dfs(0);
    k = 1;
    while (k < vert.size())
        k *= 2;
    k--;
    build(0, k, 0);
    int q;
    cin >> q;
    for (int i1 = 0; i1 < q; i1++)
    {
        int x, y, a, b, k;
        cin >> x >> y >> a >> b >> k;
        x--;
        y--;
        a--;
        b--;
        bool flag1 = false, flag2 = false, flag3 = false;
        int ab = lca(pos[a], pos[b]), ax = lca(pos[a], pos[x]), ay = lca(pos[a], pos[y]), bx = lca(pos[b], pos[x]), by = lca(pos[b], pos[y]);
        int d1 = (dist[a]+dist[b]-2*dist[ab]);
        int d2 = (dist[a]+dist[x]-2*dist[ax]+dist[b]+dist[y]-2*dist[by]+1);
        int d3 = (dist[a]+dist[y]-2*dist[ay]+dist[b]+dist[x]-2*dist[bx]+1);
        if ((d1 % 2 == k % 2 && d1 <= k) || (d2 % 2 == k % 2 && d2 <= k) || (d3 % 2 == k % 2 && d3 <= k))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > matx(5000000);
vector<int> vert, d, dist(5000000), pos(5000000), len(5000000), le(5000000);
pair<int, int> table[2200000][25];
vector<bool> used(5000000);
int k;
void dfs(int v)
{
    used[v] = true;
    pos[v] = vert.size();
    vert.push_back(v);
    d.push_back(dist[v]);
    for (int i = 0; i < matx[v].size(); i++)
        if (!used[matx[v][i]])
        {
            dist[matx[v][i]] = dist[v]+1;
            dfs(matx[v][i]);
            vert.push_back(v);
            d.push_back(dist[v]);
        }
}
void build(int n)
{
    int o = 0, kk = 2;
    for (int i = 0; i < 25; i++)
        for (int j = 0; j < n; j++)
            table[i][j] = {0, 0};
    for (int i = 0; i < n; i++)
        table[0][i] = {d[i], vert[i]};
    while (kk < n)
    {
        o++;
        for (int i = kk-1; i < n; i++)
            if (table[o-1][i].first <  table[o-1][i-(kk / 2)].first)
                table[o][i] = table[o-1][i];
            else
                table[o][i] = table[o-1][i-(kk / 2)];
        kk *= 2;
    }
    int l = 1, m = 0;
    for (int i = 0; i < 20; i++)
    {
        for (int j = 0; j < l; j++)
        {
            m++;
            len[m] = i;
            le[m] = l;
        }
        l *= 2;
    }
    len[0] = -1;
}
int lca(int u, int v)
{
    if (u > v)
        swap(u, v);
    int l = (v-u+1);
    if (table[len[l]][v].first < table[len[l]][u+le[l]-1].first)
        return table[len[l]][v].second;
    else
        return table[len[l]][u+le[l]-1].second;
}
int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        matx[x].push_back(y);
        matx[y].push_back(x);
    }
    dist[0] = 0;
    dfs(0);
    build(vert.size());
    int q;
    cin >> q;
    for (int i1 = 0; i1 < q; i1++)
    {
        int x, y, a, b, k;
        cin >> x >> y >> a >> b >> k;
        x--;
        y--;
        a--;
        b--;
        bool flag1 = false, flag2 = false, flag3 = false;
        int ab = lca(pos[a], pos[b]), ax = lca(pos[a], pos[x]), ay = lca(pos[a], pos[y]), bx = lca(pos[b], pos[x]), by = lca(pos[b], pos[y]);
        int d1 = (dist[a]+dist[b]-2*dist[ab]);
        int d2 = (dist[a]+dist[x]-2*dist[ax]+dist[b]+dist[y]-2*dist[by]+1);
        int d3 = (dist[a]+dist[y]-2*dist[ay]+dist[b]+dist[x]-2*dist[bx]+1);
        if ((d1 % 2 == k % 2 && d1 <= k) || (d2 % 2 == k % 2 && d2 <= k) || (d3 % 2 == k % 2 && d3 <= k))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> depth;
vector<vector<int>> par, adj;
int LOG = 21;

void dfs(int u = 0, int p = -1, int d = 0) {
	depth[u] = d;
	par[u][0] = p;
	for (int v : adj[u]) {
		if (v != p) {
			dfs(v, u, d + 1);
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) {
		swap(u, v);
	}
	for (int i = LOG - 1; i >= 0; i--) {
		if (depth[v] - (1 << i) >= depth[u]) {
			v = par[v][i];
			assert(v != -1);
		}
	}
	assert(depth[u] == depth[v]);
	if (u == v) return u;
	for (int i = LOG - 1; i >= 0; i--) {
		if (par[v][i] != par[u][i]) {
			v = par[v][i];
			u = par[u][i];
			assert(v != -1 && u != -1);
		}
	}
	return par[u][0];
}

int dist(int u, int v) {
	return depth[u] + depth[v] - 2 * depth[lca(u, v)];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	depth = vector<int>(n);
	par = vector<vector<int>>(n, vector<int>(LOG, -1));
	adj = vector<vector<int>>(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs();
	for (int i = 0; i < n; i++) {
		assert(lca(i, i) == i);
		for (int j = 1; j < LOG; j++) {
			if (par[i][j - 1] == -1) {
				par[i][j] = -1;
			} else {
				par[i][j] = par[par[i][j - 1]][j - 1];
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int x, y, a, b, k;
		cin >> x >> y >> a >> b >> k;
		x--, y--, a--, b--;
		int d = dist(a, b);
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, x) + dist(y, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, y) + dist(x, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		cout << "NO\n";
	}
}


#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> depth;
vector<vector<int>> par, adj;
int LOG = 1;

void dfs(int u = 0, int p = -1, int d = 0) {
	depth[u] = d;
	par[u][0] = p;
	for (int v : adj[u]) {
		if (v != p) {
			dfs(v, u, d + 1);
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) {
		swap(u, v);
	}
	for (int i = LOG - 1; i >= 0; i--) {
		if (depth[v] - (1 << i) >= depth[u]) {
			v = par[v][i];
		}
	}
	assert(depth[u] == depth[v]);
	if (u == v) return u;
	for (int i = LOG - 1; i >= 0; i--) {
		if (par[v][i] != par[u][i]) {
			v = par[v][i];
			u = par[u][i];
		}
	}
	return par[u][0];
}

int dist(int u, int v) {
	return depth[u] + depth[v] - 2 * depth[lca(u, v)];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int p2 = 1; p2 < n; p2 *= 2, LOG++);
	depth = vector<int>(n);
	par = vector<vector<int>>(n, vector<int>(LOG, -1));
	adj = vector<vector<int>>(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs();
	for (int i = 0; i < n; i++) {
		assert(lca(i, i) == i);
		for (int j = 1; j < LOG; j++) {
			if (par[i][j - 1] == -1) {
				par[i][j] = -1;
			} else {
				par[i][j] = par[par[i][j - 1]][j - 1];
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int x, y, a, b, k;
		cin >> x >> y >> a >> b >> k;
		x--, y--, a--, b--;
		int d = dist(a, b);
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, x) + dist(y, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, y) + dist(x, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		cout << "NO\n";
	}
}


#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> depth;
vector<vector<int>> par, adj;
int LOG = 21;

void dfs(int u = 0, int p = -1, int d = 0) {
	depth[u] = d;
	par[u][0] = p;
	for (int v : adj[u]) {
		if (v != p) {
			dfs(v, u, d + 1);
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) {
		swap(u, v);
	}
	for (int i = LOG - 1; i >= 0; i--) {
		if (depth[v] - (1 << i) >= depth[u]) {
			v = par[v][i];
		}
	}
	assert(depth[u] == depth[v]);
	if (u == v) return u;
	for (int i = LOG - 1; i >= 0; i--) {
		if (par[v][i] != par[u][i]) {
			v = par[v][i];
			u = par[u][i];
		}
	}
	return par[u][0];
}

int dist(int u, int v) {
	return depth[u] + depth[v] - 2 * depth[lca(u, v)];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	depth = vector<int>(n);
	par = vector<vector<int>>(n, vector<int>(LOG, -1));
	adj = vector<vector<int>>(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs();
	for (int i = 0; i < n; i++) {
		assert(lca(i, i) == i);
		for (int j = 1; j < LOG; j++) {
			if (par[i][j - 1] == -1) {
				par[i][j] = -1;
			} else {
				par[i][j] = par[par[i][j - 1]][j - 1];
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int x, y, a, b, k;
		cin >> x >> y >> a >> b >> k;
		x--, y--, a--, b--;
		int d = dist(a, b);
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, x) + dist(y, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, y) + dist(x, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		cout << "NO\n";
	}
}


#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> depth;
vector<vector<int>> par, adj;
int LOG = 21;

void dfs(int u = 1, int p = 0, int d = 0) {
	depth[u] = d;
	par[u][0] = p;
	for (int i = 1; i < LOG; i++) {
		par[u][i] = par[par[u][i - 1]][i - 1];
	}
	for (int v : adj[u]) {
		if (v != p) {
			dfs(v, u, d + 1);
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) {
		swap(u, v);
	}
	for (int i = LOG - 1; i >= 0; i--) {
		if (depth[par[v][i]] >= depth[u]) {
			v = par[v][i];
		}
	}
	assert(depth[u] == depth[v]);
	if (u == v) return u;
	for (int i = LOG - 1; i >= 0; i--) {
		if (par[v][i] != par[u][i]) {
			v = par[v][i];
			u = par[u][i];
			assert(v != -1 && u != -1);
		}
	}
	return par[u][0];
}

int dist(int u, int v) {
	return depth[u] + depth[v] - 2 * depth[lca(u, v)];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	depth = vector<int>(n + 1);
	par = vector<vector<int>>(n + 1, vector<int>(LOG));
	adj = vector<vector<int>>(n + 1);
	depth[0] = -1;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs();
	int q;
	cin >> q;
	while (q--) {
		int x, y, a, b, k;
		cin >> x >> y >> a >> b >> k;
		int d = dist(a, b);
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, x) + dist(y, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, y) + dist(x, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		cout << "NO\n";
	}
}


#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> depth;
vector<vector<int>> par, adj;
int LOG = 20;

void dfs(int u = 0, int p = -1, int d = 0) {
	depth[u] = d;
	par[u][0] = p;
	for (int v : adj[u]) {
		if (v != p) {
			dfs(v, u, d + 1);
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) {
		swap(u, v);
	}
	for (int i = LOG - 1; i >= 0; i--) {
		if (depth[v] - (1 << i) >= depth[u]) {
			v = par[v][i];
		}
	}
	assert(depth[u] == depth[v]);
	if (u == v) return u;
	for (int i = LOG - 1; i >= 0; i--) {
		if (par[v][i] != par[u][i]) {
			v = par[v][i];
			u = par[u][i];
		}
	}
	return par[u][0];
}

int dist(int u, int v) {
	return depth[u] + depth[v] - 2 * depth[lca(u, v)];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	depth = vector<int>(n);
	par = vector<vector<int>>(n, vector<int>(LOG, -1));
	adj = vector<vector<int>>(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs();
	for (int i = 0; i < n; i++) {
		assert(lca(i, i) == i);
		for (int j = 1; j < LOG; j++) {
			if (par[i][j - 1] == -1) {
				par[i][j] = -1;
			} else {
				par[i][j] = par[par[i][j - 1]][j - 1];
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int x, y, a, b, k;
		cin >> x >> y >> a >> b >> k;
		x--, y--, a--, b--;
		int d = dist(a, b);
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, x) + dist(y, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(a, y) + dist(x, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		cout << "NO\n";
	}
}


#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> depth;
vector<vector<int>> par, adj;
int LOG = 1;

void dfs(int u = 0, int p = -1, int d = 0) {
	depth[u] = d;
	par[u][0] = p;
	for (int v : adj[u]) {
		if (v != p) {
			dfs(v, u, d + 1);
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) {
		swap(u, v);
	}
	for (int i = LOG; i >= 0; i--) {
		if (depth[v] >= depth[u] + (1 << i)) {
			v = par[v][i];
		}
	}
	assert(depth[u] == depth[v]);
	for (int i = LOG; i >= 0; i--) {
		if (par[v][i] != par[u][i]) {
			v = par[v][i];
			u = par[u][i];
		}
	}
	return par[u][0];
}

int dist(int u, int v) {
	return depth[u] + depth[v] - 2 * depth[lca(u, v)];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int p2 = 1; p2 < n; p2 *= 2, LOG++);
	depth = vector<int>(n);
	par = vector<vector<int>>(n, vector<int>(LOG, -1));
	adj = vector<vector<int>>(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs();
	for (int i = 0; i < n; i++) {
		for (int j = 1; j < LOG; j++) {
			if (par[i][j - 1] == -1) {
				par[i][j] = -1;
			} else {
				par[i][j] = par[par[i][j - 1]][j - 1];
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int x, y, a, b, k;
		cin >> x >> y >> a >> b >> k;
		x--, y--, a--, b--;
		int d = dist(a, b);
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(x, a) + dist(y, b) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		d = dist(x, b) + dist(y, a) + 1;
		if (d <= k && d % 2 == k % 2) {
			cout << "YES\n";
			continue;
		}
		cout << "NO\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
vector<int>g[maxn];
int fa[maxn][20];
int depth[maxn];
void init(int x){
    if(x == 1){
        depth[x] = 0;
        for(int i = 0;i<20;i++)
            fa[x][i] = 1;
    }
    else{
        depth[x] = depth[fa[x][0]]+1;
        for(int i = 1;i<20;i++)
            fa[x][i] = fa[fa[x][i-1]][i-1];
    }
    for(int y:g[x])
        if(y != fa[x][0]){
            fa[y][0] = x;
            init(y);
        }
}
int dis(int x,int y){
    int sum = 0;
    sum = depth[x] + depth[y];
    while(depth[x] != depth[y]){
        if(depth[y] > depth[x])
            swap(x,y);
        for(int i = 0;i<20;i++){
            if(depth[fa[x][i]] == depth[y]){
                x = fa[x][i];
                break;
            }
            if(depth[fa[x][i]] < depth[y]){
                x = fa[x][i-1];
                break;
            }
        }
    }
    if(x != y)
        for(int i = 0;i<20;i++)
            if(fa[x][i] == fa[y][i])
                x = y = fa[x][i];
    sum -= 2*depth[x];
    return sum;
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i = 1;i<n;i++){
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(1);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y,a,b,k;
        scanf("%d%d%d%d%d",&x,&y,&a,&b,&k);
        int dis1 = dis(a,b);
        if(dis1 <= k && dis1%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis21 = dis(a,x);
        int dis22 = dis(y,b);
        int dis2  = dis21+dis22+1;
        if(dis2 <= k && dis2%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis31 = dis(a,y);
        int dis32 = dis(x,b);
        int dis3  = dis31+dis32+1;
        if(dis2 <= k && dis3%2 == k%2){
            printf("YES\n");
            continue;
        }
        printf("NO\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
vector<int>g[maxn];
int fa[maxn][20];
int depth[maxn];
void init(int x){
    if(x == 1){
        depth[x] = 0;
        for(int i = 0;i<20;i++)
            fa[x][i] = 1;
    }
    else{
        depth[x] = depth[fa[x][0]]+1;
        for(int i = 1;i<20;i++)
            fa[x][i] = fa[fa[x][i-1]][i-1];
    }
    for(int y:g[x])
        if(y != fa[x][0]){
            fa[y][0] = x;
            init(y);
        }
}
int dis(int x,int y){
    int sum = 0;
    sum = depth[x] + depth[y];
    while(depth[x] != depth[y]){
        if(depth[y] > depth[x])
            swap(x,y);
        for(int i = 0;i<20;i++){
            if(depth[fa[x][i]] == depth[y]){
                x = fa[x][i];
                break;
            }
            if(depth[fa[x][i]] < depth[y]){
                x = fa[x][i-1];
                break;
            }
        }
    }
    if(x != y)
        for(int i = 0;i<20;i++)
            if(fa[x][i] == fa[y][i])
                x = y = fa[x][i];
    sum -= 2*depth[x];
    return sum;
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i = 1;i<n;i++){
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(1);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y,a,b,k;
        scanf("%d%d%d%d%d",&x,&y,&a,&b,&k);
        int dis1 = dis(a,b);
        if(dis1 <= k && dis1%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis21 = dis(a,x);
        int dis22 = dis(y,b);
        int dis2  = dis21+dis22+1;
        if(dis2 <= k && dis2%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis31 = dis(a,y);
        int dis32 = dis(x,b);
        int dis3  = dis31+dis32+1;
        if(dis3 <= k && dis3%2 == k%2){
            printf("YES\n");
            continue;
        }
        printf("NO\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+5;
vector<int>g[maxn];
int fa[maxn][20];
int depth[maxn];
void init(int x){
    if(x == 1){
        depth[x] = 0;
        for(int i = 0;i<20;i++)
            fa[x][i] = 0;
    }
    else{
        depth[x] = depth[fa[x][0]]+1;
        for(int i = 1;i<20;i++)
            fa[x][i] = fa[fa[x][i-1]][i-1];
    }
    for(int y:g[x])
        if(y != fa[x][0]){
            fa[y][0] = x;
            init(y);
        }
}
int dis(int x,int y){
    int sum = 0;
    sum = depth[x] + depth[y];
    if(depth[y] > depth[x])
        swap(x,y);
    for(int i = 20;i>=0;i--)
        if(depth[fa[x][i]] >= depth[y])
            x = fa[x][i];
    if(x != y){
        for(int i = 20-1;i>=0;i--)
            if(fa[x][i] != fa[y][i])
                x = fa[x][i],y = fa[y][i];
    }
    sum -= 2*depth[x];
    return sum;
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i = 1;i<n;i++){
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(1);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y,a,b,k;
        scanf("%d%d%d%d%d",&x,&y,&a,&b,&k);
        int dis1 = dis(a,b);
        if(dis1 <= k && dis1%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis21 = dis(a,x);
        int dis22 = dis(y,b);
        int dis2  = dis21+dis22+1;
        if(dis2 <= k && dis2%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis31 = dis(a,y);
        int dis32 = dis(x,b);
        int dis3  = dis31+dis32+1;
        if(dis3 <= k && dis3%2 == k%2){
            printf("YES\n");
            continue;
        }
        printf("NO\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+5;
vector<int>g[maxn];
int fa[maxn][20];
int depth[maxn];
void init(int x){
    if(x == 1){
        depth[x] = 0;
        for(int i = 0;i<20;i++)
            fa[x][i] = 1;
    }
    else{
        depth[x] = depth[fa[x][0]]+1;
        for(int i = 1;i<20;i++)
            fa[x][i] = fa[fa[x][i-1]][i-1];
    }
    for(int y:g[x])
        if(y != fa[x][0]){
            fa[y][0] = x;
            init(y);
        }
}
int dis(int x,int y){
    int sum = 0;
    sum = depth[x] + depth[y];
    while(depth[x] != depth[y]){
        if(depth[y] > depth[x])
            swap(x,y);
        for(int i = 0;i<20;i++){
            if(depth[fa[x][i]] == depth[y]){
                x = fa[x][i];
                break;
            }
            if(depth[fa[x][i]] < depth[y]){
                x = fa[x][i-1];
                break;
            }
        }
    }
    if(x != y)
        for(int i = 0;i<20;i++){
            if(fa[x][i] == fa[y][i]){
                x = y = fa[x][i];
                break;
            }
        }
    sum -= 2*depth[x];
    return sum;
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i = 1;i<n;i++){
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(1);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y,a,b,k;
        scanf("%d%d%d%d%d",&x,&y,&a,&b,&k);
        int dis1 = dis(a,b);
        if(dis1 <= k && dis1%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis21 = dis(a,x);
        int dis22 = dis(y,b);
        int dis2  = dis21+dis22+1;
        if(dis2 <= k && dis2%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis31 = dis(a,y);
        int dis32 = dis(x,b);
        int dis3  = dis31+dis32+1;
        if(dis3 <= k && dis3%2 == k%2){
            printf("YES\n");
            continue;
        }
        printf("NO\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+5;
vector<int>g[maxn];
int fa[maxn][22];
int depth[maxn];
void init(int x){
    if(x == 1){
        depth[x] = 0;
        for(int i = 0;i<=20;i++)
            fa[x][i] = 0;
    }
    else{
        depth[x] = depth[fa[x][0]]+1;
        for(int i = 1;i<=20;i++)
            fa[x][i] = fa[fa[x][i-1]][i-1];
    }
    for(int y:g[x]){
        if(y != fa[x][0]){
            fa[y][0] = x;
            init(y);
        }
    }
}
int dis(int x,int y){
    int sum = 0;
    sum = depth[x] + depth[y];
    if(depth[y] > depth[x])
        swap(x,y);
    for(int i = 20;i>=0;i--)
        if(depth[fa[x][i]] >= depth[y])
            x = fa[x][i];
    if(x != y){
        for(int i = 20;i>=0;i--)
            if(fa[x][i] != fa[y][i])
                x = fa[x][i],y = fa[y][i];
    }
    sum -= 2*depth[x];
    return sum;
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i = 1;i<n;i++){
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(1);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y,a,b,k;
        scanf("%d%d%d%d%d",&x,&y,&a,&b,&k);
        int dis1 = dis(a,b);
        if(dis1 <= k && dis1%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis21 = dis(a,x);
        int dis22 = dis(y,b);
        int dis2  = dis21+dis22+1;
        if(dis2 <= k && dis2%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis31 = dis(a,y);
        int dis32 = dis(x,b);
        int dis3  = dis31+dis32+1;
        if(dis3 <= k && dis3%2 == k%2){
            printf("YES\n");
            continue;
        }
        printf("NO\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
vector<int>g[maxn];
int fa[maxn][20];
int depth[maxn];
void init(int x){
    if(x == 1){
        depth[x] = 0;
        for(int i = 0;i<20;i++)
            fa[x][i] = 1;
    }
    else{
        depth[x] = depth[fa[x][0]]+1;
        for(int i = 1;i<20;i++)
            fa[x][i] = fa[fa[x][i-1]][i-1];
    }
    for(int y:g[x])
        if(y != fa[x][0]){
            fa[y][0] = x;
            init(y);
        }
}
int dis(int x,int y){
    int sum = 0;
    sum = depth[x] + depth[y];
    while(depth[x] != depth[y]){
        if(depth[y] > depth[x])
            swap(x,y);
        for(int i = 0;i<20;i++){
            if(depth[fa[x][i]] == depth[y]){
                x = fa[x][i];
                break;
            }
            if(depth[fa[x][i]] < depth[y]){
                x = fa[x][i-1];
                break;
            }
        }
    }
    if(x != y)
        for(int i = 0;i<20;i++){
            if(fa[x][i] == fa[y][i]){
                x = y = fa[x][i];
                break;
            }
        }
    sum -= 2*depth[x];
    return sum;
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i = 1;i<n;i++){
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(1);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y,a,b,k;
        scanf("%d%d%d%d%d",&x,&y,&a,&b,&k);
        int dis1 = dis(a,b);
        if(dis1 <= k && dis1%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis21 = dis(a,x);
        int dis22 = dis(y,b);
        int dis2  = dis21+dis22+1;
        if(dis2 <= k && dis2%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis31 = dis(a,y);
        int dis32 = dis(x,b);
        int dis3  = dis31+dis32+1;
        if(dis3 <= k && dis3%2 == k%2){
            printf("YES\n");
            continue;
        }
        printf("NO\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+5;
vector<int>g[maxn];
int fa[maxn][22];
int depth[maxn];
void init(int x){
    if(x == 1){
        depth[x] = 0;
        for(int i = 0;i<=20;i++)
            fa[x][i] = 0;
    }
    else{
        depth[x] = depth[fa[x][0]]+1;
        for(int i = 1;i<=20;i++)
            fa[x][i] = fa[fa[x][i-1]][i-1];
    }
    for(int y:g[x]){
        if(y != fa[x][0]){
            fa[y][0] = x;
            init(y);
        }
    }
}
int dis(int x,int y){
    int sum = 0;
    sum = depth[x] + depth[y];
    if(depth[y] > depth[x])
        swap(x,y);
    for(int i = 20;i>=0;i--)
        if(depth[fa[x][i]] >= depth[y])
            x = fa[x][i];
    if(x != y){
        for(int i = 20;i>=0;i--)
            if(fa[x][i] != fa[y][i])
                x = fa[x][i],y = fa[y][i];
        x = fa[x][0];
        y = fa[y][0];
    }

    sum -= 2*depth[x];
    return sum;
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i = 1;i<n;i++){
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init(1);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y,a,b,k;
        scanf("%d%d%d%d%d",&x,&y,&a,&b,&k);
        int dis1 = dis(a,b);
        if(dis1 <= k && dis1%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis21 = dis(a,x);
        int dis22 = dis(y,b);
        int dis2  = dis21+dis22+1;
        if(dis2 <= k && dis2%2 == k%2){
            printf("YES\n");
            continue;
        }
        int dis31 = dis(a,y);
        int dis32 = dis(x,b);
        int dis3  = dis31+dis32+1;
        if(dis3 <= k && dis3%2 == k%2){
            printf("YES\n");
            continue;
        }
        printf("NO\n");
    }
    return 0;
}


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;

    public:
        std::vector< std::vector< edge > > graph;
        std::vector< int > depth;
        std::vector< Value > w_depth;
        std::vector< std::vector< int > >table;
        std::vector< int > &tail;
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        int q_xy=lca.query(x,y);
        auto dash = [&] (int u) {
            int ux=lca.query(u,x);
            int uy=lca.query(u,y);
            int u_=lca.depth.at(ux)<lca.depth.at(uy)?uy:ux;
            return lca.query(u_,q_xy)==q_xy?u_:q_xy;
        };
        auto bonus = [&] {
            int D=lca.row_distance(x,y)+1;
            if(D%2==0)return -1;
            int a_=dash(a),b_=dash(b);
            if(a_!=b_)return D-2*lca.row_distance(a_,b_);
            if(lca.query(a_,q_xy)==q_xy)return D+2*lca.row_distance(lca.query(a,b),a_);
            int q_xya=lca.query(q_xy,a),q_xyb=lca.query(q_xy,b);
            int c=lca.depth.at(q_xya)<lca.depth.at(q_xyb)?q_xyb:q_xya;
            return D+2*lca.row_distance(c,q_xya);
        }();
        int d=std::min({
            lca.row_distance(a,b),
            lca.row_distance(a,x)+1+lca.row_distance(y,b),
            lca.row_distance(a,y)+1+lca.row_distance(x,b)
        });
        std::cout << (d<=k&&((bonus!=-1&&d+bonus<=k)||(k-d)%2==0)?"YES":"NO") << std::endl;
    }
    return 0;
}

/*
LCA などで、2頂点距離クエリに答えられるようにしておきます。
最短距離は、
- d(a,b)
- d(a,x)+1+d(y,b)
- d(a,y)+1+d(x,b)
の最小です。
偶奇は基本的にあっていて欲しいです。

距離の偶数なものを結ぶと奇数長 (=D)サイクルができて、ボーナスタイムです。
なもりでおなじ枝かどうかを確認です。
なもりサイクルに引いてきた点を a', b' としましょう。
これは、x, y との LCA のうち深いほうです。

a'!=b'のとき、別の枝です。
ボーナスは、D - 2*d(a',b') 以上の余裕が必要です。

a'==b'のとき、おなじ枝です。
ボーナスは、c=LCA(a,b) として、D + 2*d(c',c) 以上の余裕が必要です。
*/


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;

    public:
        std::vector< std::vector< edge > > graph;
        std::vector< int > depth;
        std::vector< Value > w_depth;
        std::vector< std::vector< int > >table;
        std::vector< int > &tail;
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        int q_ab=lca.query(a,b);
        auto dash = [&] (int u) {
            int ux=lca.query(u,x);
            int uy=lca.query(u,y);
            int u_=lca.depth.at(ux)<lca.depth.at(uy)?uy:ux;
            return lca.query(u_,q_ab)==q_ab?u_:q_ab;
        };
        auto bonus = [&] {
            int D=lca.row_distance(x,y)+1;
            if(D%2==0)return -1;
            int a_=dash(a),b_=dash(b);
            return a_==b_
                ? D+2*lca.row_distance(lca.query(a,b),a_)
                : D-2*lca.row_distance(a_,b_);
        }();
        int d=std::min({
            lca.row_distance(a,b),
            lca.row_distance(a,x)+1+lca.row_distance(y,b),
            lca.row_distance(a,y)+1+lca.row_distance(x,b)
        });
        std::cout << (d<=k&&((bonus!=-1&&d+bonus<=k)||(k-d)%2==0)?"YES":"NO") << std::endl;
    }
    return 0;
}

/*
LCA などで、2頂点距離クエリに答えられるようにしておきます。
最短距離は、
- d(a,b)
- d(a,x)+1+d(y,b)
- d(a,y)+1+d(x,b)
の最小です。
偶奇は基本的にあっていて欲しいです。

距離の偶数なものを結ぶと奇数長 (=D)サイクルができて、ボーナスタイムです。
なもりでおなじ枝かどうかを確認です。
なもりサイクルに引いてきた点を a', b' としましょう。
これは、x, y との LCA のうち深いほうです。

a'!=b'のとき、別の枝です。
ボーナスは、D - 2*d(a',b') 以上の余裕が必要です。

a'==b'のとき、おなじ枝です。
ボーナスは、c=LCA(a,b) として、D + 2*d(c',c) 以上の余裕が必要です。
*/


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;

    public:
        std::vector< std::vector< edge > > graph;
        std::vector< int > depth;
        std::vector< Value > w_depth;
        std::vector< std::vector< int > >table;
        std::vector< int > &tail;
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }

        bool is_under(int u, int v) {
            return query(u,v)==v;
        };
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        int z=lca.query(x,y);
        auto dash=[&](int u){
            if(!lca.is_under(u,z))return z;
            int with_x=lca.query(u,x);
            int with_y=lca.query(u,y);
            return lca.depth.at(with_x)<lca.depth.at(with_y)?with_y:with_x;
        };
        auto bonus = [&] {
            int D=lca.row_distance(x,y)+1;
            if(D%2==0)return-1;
            int a_=dash(a),b_=dash(b);
            if(a_!=b_)return D-2*lca.row_distance(a_,b_);
            if(lca.is_under(a_,z))return D+2*lca.row_distance(lca.query(a,b),a_);
            return D+2*(lca.row_distance(a,z)+lca.row_distance(b,z)-lca.row_distance(a,b));
        }();
        int d=std::min({
            lca.row_distance(a,b),
            lca.row_distance(a,x)+1+lca.row_distance(y,b),
            lca.row_distance(a,y)+1+lca.row_distance(x,b)
        });
        std::cout << (d<=k&&((bonus!=-1&&d+bonus<=k)||(k-d)%2==0)?"YES":"NO") << std::endl;
    }
    return 0;
}

/*
LCA などで、2頂点距離クエリに答えられるようにしておきます。
最短距離は、
- d(a,b)
- d(a,x)+1+d(y,b)
- d(a,y)+1+d(x,b)
の最小です。
偶奇は基本的にあっていて欲しいです。

距離の偶数なものを結ぶと奇数長 (=D)サイクルができて、ボーナスタイムです。
なもりでおなじ枝かどうかを確認です。
なもりサイクルに引いてきた点を a', b' としましょう。
これは、x, y との LCA のうち深いほうです。

a'!=b'のとき、別の枝です。
ボーナスは、D - 2*d(a',b') 以上の余裕が必要です。

a'==b'のとき、おなじ枝です。
ボーナスは、c=LCA(a,b) として、D + 2*d(c',c) 以上の余裕が必要です。
*/


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;

    public:
        std::vector< std::vector< edge > > graph;
        std::vector< int > depth;
        std::vector< Value > w_depth;
        std::vector< std::vector< int > >table;
        std::vector< int > &tail;
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }

        bool is_under(int u, int v) {
            return query(u,v)==v;
        };
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        int ab=lca.row_distance(a,b);
        int ax=lca.row_distance(a,x);
        int ay=lca.row_distance(a,y);
        int bx=lca.row_distance(b,x);
        int by=lca.row_distance(b,y);
        // 辺 x,y を通らないルートをためします。
        if(ab<=k&&(k-ab)%2==0){
            std::cout << "YES" << std::endl;
            continue;
        }
        // 辺 x,y を一度だけ通るルートをためします。
        int d=std::min(ax+1+by,ay+1+bx);
        if(d<=k&&(k-d)%2==0){
            std::cout << "YES" << std::endl;
            continue;
        }
        std::cout << "NO" << std::endl;
    }
    return 0;
}


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;

    public:
        std::vector< std::vector< edge > > graph;
        std::vector< int > depth;
        std::vector< Value > w_depth;
        std::vector< std::vector< int > >table;
        std::vector< int > &tail;
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }

        bool is_under(int u, int v) {
            return query(u,v)==v;
        };
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        int z=lca.query(x,y);
        auto dash=[&](int u){
            if(!lca.is_under(u,z))return z;
            int with_x=lca.query(u,x);
            int with_y=lca.query(u,y);
            return lca.depth.at(with_x)<lca.depth.at(with_y)?with_y:with_x;
        };
        auto bonus = [&] {
            int D=lca.row_distance(x,y)+1;
            if(D%2==0)return-1;
            int a_=dash(a),b_=dash(b);
            if(a_!=b_)return D-2*lca.row_distance(a_,b_);
            if(a_!=z)return D+2*lca.row_distance(lca.query(a,b),a_);
            return D+2*(lca.row_distance(a,z)+lca.row_distance(b,z)-lca.row_distance(a,b));
        }();
        int d=std::min({
            lca.row_distance(a,b),
            lca.row_distance(a,x)+1+lca.row_distance(y,b),
            lca.row_distance(a,y)+1+lca.row_distance(x,b)
        });
        std::cout << (d<=k&&((bonus!=-1&&d+bonus<=k)||(k-d)%2==0)?"YES":"NO") << std::endl;
    }
    return 0;
}

/*
LCA などで、2頂点距離クエリに答えられるようにしておきます。
最短距離は、
- d(a,b)
- d(a,x)+1+d(y,b)
- d(a,y)+1+d(x,b)
の最小です。
偶奇は基本的にあっていて欲しいです。

距離の偶数なものを結ぶと奇数長 (=D)サイクルができて、ボーナスタイムです。
なもりでおなじ枝かどうかを確認です。
なもりサイクルに引いてきた点を a', b' としましょう。
これは、x, y との LCA のうち深いほうです。

a'!=b'のとき、別の枝です。
ボーナスは、D - 2*d(a',b') 以上の余裕が必要です。

a'==b'のとき、おなじ枝です。
ボーナスは、c=LCA(a,b) として、D + 2*d(c',c) 以上の余裕が必要です。
*/


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;

    public:
        std::vector< std::vector< edge > > graph;
        std::vector< int > depth;
        std::vector< Value > w_depth;
        std::vector< std::vector< int > >table;
        std::vector< int > &tail;
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        int q_xy=lca.query(x,y);
        auto dash = [&] (int u) {
            int ux=lca.query(u,x);
            int uy=lca.query(u,y);
            int u_=lca.depth.at(ux)<lca.depth.at(uy)?uy:ux;
            return lca.query(u_,q_xy)==q_xy?u_:q_xy;
        };
        auto bonus = [&] {
            int D=lca.row_distance(x,y)+1;
            if(D%2==0)return -1;
            int a_=dash(a),b_=dash(b);
            if(a_!=b_)return D-2*lca.row_distance(a_,b_);
            if(lca.query(a_,q_xy)==q_xy)return D+2*lca.row_distance(lca.query(a,b),a_);
            int q_xya=lca.query(q_xy,a),q_xyb=lca.query(q_xy,b);
            int c=lca.depth.at(q_xya)<lca.depth.at(q_xyb)?q_xyb:q_xya;
            return lca.row_distance(c,q_xya);
        }();
        int d=std::min({
            lca.row_distance(a,b),
            lca.row_distance(a,x)+1+lca.row_distance(y,b),
            lca.row_distance(a,y)+1+lca.row_distance(x,b)
        });
        std::cout << (d<=k&&((bonus!=-1&&d+bonus<=k)||(k-d)%2==0)?"YES":"NO") << std::endl;
    }
    return 0;
}

/*
LCA などで、2頂点距離クエリに答えられるようにしておきます。
最短距離は、
- d(a,b)
- d(a,x)+1+d(y,b)
- d(a,y)+1+d(x,b)
の最小です。
偶奇は基本的にあっていて欲しいです。

距離の偶数なものを結ぶと奇数長 (=D)サイクルができて、ボーナスタイムです。
なもりでおなじ枝かどうかを確認です。
なもりサイクルに引いてきた点を a', b' としましょう。
これは、x, y との LCA のうち深いほうです。

a'!=b'のとき、別の枝です。
ボーナスは、D - 2*d(a',b') 以上の余裕が必要です。

a'==b'のとき、おなじ枝です。
ボーナスは、c=LCA(a,b) として、D + 2*d(c',c) 以上の余裕が必要です。
*/


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;

    public:
        std::vector< std::vector< edge > > graph;
        std::vector< int > depth;
        std::vector< Value > w_depth;
        std::vector< std::vector< int > >table;
        std::vector< int > &tail;
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        auto bonus = [&] {
            int D=lca.row_distance(x,y)+1;
            if(D%2==0)return -1;
            int ax=lca.query(a,x);
            int ay=lca.query(a,y);
            int bx=lca.query(b,x);
            int by=lca.query(b,y);
            int a_=lca.depth.at(ax)<lca.depth.at(ay)?ay:ax;
            int b_=lca.depth.at(bx)<lca.depth.at(by)?by:bx;
            return a_==b_
                ? D+2*lca.row_distance(lca.query(a,b),a_)
                : D-2*lca.row_distance(a_,b_);
        }();
        int d=std::min({
            lca.row_distance(a,b),
            lca.row_distance(a,x)+1+lca.row_distance(y,b),
            lca.row_distance(a,y)+1+lca.row_distance(x,b)
        });
        std::cout << (d<=k&&((bonus!=-1&&d+bonus<=k)||(k-d)%2==0)?"YES":"NO") << std::endl;
    }
    return 0;
}

/*
LCA などで、2頂点距離クエリに答えられるようにしておきます。
最短距離は、
- d(a,b)
- d(a,x)+1+d(y,b)
- d(a,y)+1+d(x,b)
の最小です。
偶奇は基本的にあっていて欲しいです。

距離の偶数なものを結ぶと奇数長 (=D)サイクルができて、ボーナスタイムです。
なもりでおなじ枝かどうかを確認です。
なもりサイクルに引いてきた点を a', b' としましょう。
これは、x, y との LCA のうち深いほうです。

a'!=b'のとき、別の枝です。
ボーナスは、D - 2*d(a',b') 以上の余裕が必要です。

a'==b'のとき、おなじ枝です。
ボーナスは、c=LCA(a,b) として、D + 2*d(c',c) 以上の余裕が必要です。
*/


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;

    public:
        std::vector< std::vector< edge > > graph;
        std::vector< int > depth;
        std::vector< Value > w_depth;
        std::vector< std::vector< int > >table;
        std::vector< int > &tail;
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }

        bool is_under(int u, int v) {
            return query(u,v)==v;
        };
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        int z=lca.query(x,y);
        auto dash=[&](int u){
            if(!lca.is_under(u,z))return z;
            int with_x=lca.query(u,x);
            int with_y=lca.query(u,y);
            return lca.depth.at(with_x)<lca.depth.at(with_y)?with_y:with_x;
        };
        auto bonus = [&] {
            int D=lca.row_distance(x,y)+1;
            if(D%2==0)return-1;
            int a_=dash(a),b_=dash(b);
            if(a_!=b_)return D-2*lca.row_distance(a_,b_);
            if(a_!=z)return D+2*lca.row_distance(lca.query(a,b),a_);
            return D+(lca.row_distance(a,z)+lca.row_distance(b,z)-lca.row_distance(a,b));
        }();
        int d=std::min({
            lca.row_distance(a,b),
            lca.row_distance(a,x)+1+lca.row_distance(y,b),
            lca.row_distance(a,y)+1+lca.row_distance(x,b)
        });
        std::cout << (d<=k&&((bonus!=-1&&d+bonus<=k)||(k-d)%2==0)?"YES":"NO") << std::endl;
    }
    return 0;
}

/*
LCA などで、2頂点距離クエリに答えられるようにしておきます。
最短距離は、
- d(a,b)
- d(a,x)+1+d(y,b)
- d(a,y)+1+d(x,b)
の最小です。
偶奇は基本的にあっていて欲しいです。

距離の偶数なものを結ぶと奇数長 (=D)サイクルができて、ボーナスタイムです。
なもりでおなじ枝かどうかを確認です。
なもりサイクルに引いてきた点を a', b' としましょう。
これは、x, y との LCA のうち深いほうです。

a'!=b'のとき、別の枝です。
ボーナスは、D - 2*d(a',b') 以上の余裕が必要です。

a'==b'のとき、おなじ枝です。
ボーナスは、c=LCA(a,b) として、D + 2*d(c',c) 以上の余裕が必要です。
*/


#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < class Value >
class lowest_common_ancestor {
        struct edge {
            int to; Value cost;
            edge(int to, Value cost) : to(to), cost(cost){}
        };
        int n, lg, powlg;
        std::vector< std::vector< edge > > graph;
        std::vector< int >                                 depth;
        std::vector< Value >                             w_depth;
        std::vector< std::vector< int > >    table;
        std::vector< int > &                             tail;

    public:
        using cost_type = Value;
        lowest_common_ancestor(int n) :
            n(n),
            lg(std::log2(n)),
            powlg(std::pow(2, lg)),
            graph(n),
            depth(n, 0),
            w_depth(n, 0),
            table(lg + 1, std::vector< int >(n)),
            tail(table.back())
            {}

        void insert (int u, int v, Value cost = 1) {
            graph.at(u).emplace_back(v, cost);
            graph.at(v).emplace_back(u, cost);
        }

        void build (int root = 0) {
            auto dfs = [&](auto f, int crr, int p) -> void {
                tail.at(crr) = p;
                for (auto const& e : graph.at(crr)) {
                    if (e.to == p) continue;
                    depth.at(e.to) = depth.at(crr) + 1;
                    w_depth.at(e.to) = w_depth.at(crr) + e.cost;
                    f(f, e.to, crr);
                }
            };
            dfs(dfs, root, root);
            for (int p = lg; p >= 1; p--) {
                auto & crr = table.at(p);
                auto & nxt = table.at(p - 1);
                for (int i = 0; i < n; i++) {
                    nxt.at(i) = crr.at(crr.at(i));
                }
            }
        }

        auto query(int u, int v) const -> int {
            if (depth.at(u) < depth.at(v)) std::swap(u, v);
            auto diff = depth.at(u) - depth.at(v);
            if (diff > 0) {
                int coeff = powlg;
                for (auto const & row : table) {
                    if (coeff < diff) {
                        u = row.at(u);
                        diff -= coeff;
                    }
                    coeff /= 2;
                }
                u = tail.at(u);
                diff--;
            }
            assert(diff == 0);
            assert(depth.at(u) == depth.at(v));
            if (u == v) return u;
            for (auto const & row : table) {
                auto next_u = row.at(u);
                auto next_v = row.at(v);
                if (next_u != next_v) {
                    u = next_u;
                    v = next_v;
                }
            }
            assert(u != v);
            u = tail.at(u), v = tail.at(v), assert(u == v);
            return u;
        }

        auto row_distance (int u, int v) const -> int {
            return depth.at(u) + depth.at(v) - 2 * depth.at(query(u, v));
        }

        auto weighted_distance (int u, int v) const -> Value {
            return w_depth.at(u) + w_depth.at(v) - 2 * w_depth.at(query(u, v));
        }
};

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    lowest_common_ancestor<int>lca(n);
    loop(n-1){
        int u, v; std::cin >> u >> v;
        lca.insert(u-1,v-1);
    }
    lca.build();
    int q; std::cin >> q;
    loop(q){
        int x, y, a, b, k;
        std::cin >> x >> y >> a >> b >> k;
        x--,y--,a--,b--;
        bool bonus=lca.row_distance(x,y)%2==0;
        int d=std::min({
            lca.row_distance(a,b),
            lca.row_distance(a,x)+1+lca.row_distance(y,b),
            lca.row_distance(a,y)+1+lca.row_distance(x,b)
        });
        std::cout << (d<=k&&(bonus||(k-d)%2==0)?"YES":"NO") << std::endl;
    }
    return 0;
}

/*
LCA などで、2頂点距離クエリに答えられるようにしておきます。
距離の偶数なものを結ぶと奇数長サイクルができて、ボーナスタイムです。
最短距離は、
- d(a,b)
- d(a,x)+1+d(y,b)
- d(a,y)+1+d(x,b)
の最小です。
*/