#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e5;
int up[N][20], d[N];
vector <int> g[N];
void dfs(int v, int p){
up[v][0] = p;
for(int i = 1; i < 20; i++){
up[v][i] = up[up[v][i - 1]][i - 1];
}
for(int u:g[v]){
if(u != p) {
d[u] = d[v] + 1;
dfs(u, v);
}
}
}
int get(int v, int p){
for(int i = 0; i < 20; i++){
if(p & (1 << i)) v = up[v][i];
if(v == 0) break;
}
return max(v, 0ll);
}
bool isAncestor(int v, int u){
if(u == v) return true;
if(d[v] >= d[u]) return false;
u = get(u, d[u] - d[v]);
return v == u;
}
signed main(){
int n;
cin >> n;
for(int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 0);
int q;
cin >> q;
while(q--){
int u, v;
cin >> u >> v;
if(not isAncestor(u, v)) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCmNvbnN0IGludCBOID0gM2U1OwppbnQgdXBbTl1bMjBdLCBkW05dOwp2ZWN0b3IgPGludD4gZ1tOXTsKdm9pZCBkZnMoaW50IHYsIGludCBwKXsKICAgIHVwW3ZdWzBdID0gcDsKICAgIGZvcihpbnQgaSA9IDE7IGkgPCAyMDsgaSsrKXsKICAgICAgICB1cFt2XVtpXSA9IHVwW3VwW3ZdW2kgLSAxXV1baSAtIDFdOwogICAgfQogICAgZm9yKGludCB1Omdbdl0pewogICAgICAgIGlmKHUgIT0gcCkgewogICAgICAgICAgICBkW3VdID0gZFt2XSArIDE7CiAgICAgICAgICAgIGRmcyh1LCB2KTsKICAgICAgICB9CiAgICB9Cn0KaW50IGdldChpbnQgdiwgaW50IHApewogICAgZm9yKGludCBpID0gMDsgaSA8IDIwOyBpKyspewogICAgICAgIGlmKHAgJiAoMSA8PCBpKSkgdiA9IHVwW3ZdW2ldOwogICAgICAgIGlmKHYgPT0gMCkgYnJlYWs7CiAgICB9CiAgICByZXR1cm4gbWF4KHYsIDBsbCk7Cn0KYm9vbCBpc0FuY2VzdG9yKGludCB2LCBpbnQgdSl7CiAgICBpZih1ID09IHYpIHJldHVybiB0cnVlOwogICAgaWYoZFt2XSA+PSBkW3VdKSByZXR1cm4gZmFsc2U7CiAgICB1ID0gZ2V0KHUsIGRbdV0gLSBkW3ZdKTsKICAgIHJldHVybiB2ID09IHU7Cn0Kc2lnbmVkIG1haW4oKXsKICAgIGludCBuOwogICAgY2luID4+IG47CiAgICBmb3IoaW50IGkgPSAxOyBpIDwgbjsgaSsrKXsKICAgICAgICBpbnQgdSwgdjsKICAgICAgICBjaW4gPj4gdSA+PiB2OwogICAgICAgIGdbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgIGdbdl0ucHVzaF9iYWNrKHUpOwogICAgfQogICAgZGZzKDEsIDApOwogICAgaW50IHE7CiAgICBjaW4gPj4gcTsKICAgIHdoaWxlKHEtLSl7CiAgICAgICAgaW50IHUsIHY7CiAgICAgICAgY2luID4+IHUgPj4gdjsKICAgICAgICBpZihub3QgaXNBbmNlc3Rvcih1LCB2KSkgY291dCA8PCAiWUVTXG4iOwogICAgICAgIGVsc2UgY291dCA8PCAiTk9cbiI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==