#include <bits/stdc++.h>   using namespace std;   void read(int &n) {     n = 0;     int s = 1;     char c;     for (; (c = getchar()) >  9  || c <  0 ;)       if (c ==  - ) s = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) n = (n << 1) + (n << 3) + c - 48;     n *= s;   }   void write(int n) {     if (!n) putchar(48);     int t = 0, b[20];     for (; n; n /= 10) b[++t] = n % 10;     while (t) putchar(b[t--] + 48);   }   int f[18][200100], nxt[18][200100], m, n, q, deep[200100], fir[200100],       nex[200100], to[200100], top, son[10001001][2], siz[10001001], cnt,       rt[200100], dfl[200100], dfr[200100], mn[200100], opl, opr;   struct dot {     int a, b;   } a[200100 + 200100];   bool cmp(dot a, dot b) { return a.a < b.a; }   void dfs(int x) {     ++deep[x];     dfl[x] = dfr[x] = ++top;     for (int i = fir[x]; i; i = nex[i])       deep[to[i]] = deep[x], dfs(to[i]), dfr[x] = dfr[to[i]];   }   int lca(int x, int y) {     if (deep[x] > deep[y]) return lca(y, x);     for (int i(17), _E_(0); i >= _E_; --i)       if (deep[f[i][y]] >= deep[x]) y = f[i][y];     if (x == y) return x;     for (int i(17), _E_(0); i >= _E_; --i)       if (f[i][y] ^ f[i][x]) x = f[i][x], y = f[i][y];     return f[0][x];   }   void doit(int x) {     for (int i = fir[x]; i; i = nex[i]) {       doit(to[i]);       mn[x] = deep[mn[to[i]]] < deep[mn[x]] ? mn[to[i]] : mn[x];     }     if (x ^ mn[x]) nxt[0][x] = mn[x];   }   void update(int u, int &v, int h, int t) {     v = ++cnt;     siz[v] = siz[u] + 1;     son[v][0] = son[u][0];     son[v][1] = son[u][1];     if (h == t) return;     int m = h + t >> 1;     if (opl <= m)       update(son[u][0], son[v][0], h, m);     else       update(son[u][1], son[v][1], m + 1, t);   }   int query(int w, int h, int t) {     if (opl > t || opr < h || !w) return 0;     if (opl <= h && opr >= t) return siz[w];     int m = h + t >> 1, res = 0;     if (opl <= m) res += query(son[w][0], h, m);     if (opr > m) res += query(son[w][1], m + 1, t);     return res;   }   int exist(int u, int v) {     int sum = 0;     opr = dfr[v];     opl = dfl[v];     sum += query(rt[dfr[u]], 1, n);     opr = dfr[v];     opl = dfl[v];     sum -= query(rt[dfl[u] - 1], 1, n);     return sum > 0;   }   int main() {     scanf( %d , &n);     for (int i(1), _E_(n); i <= _E_; ++i) mn[i] = i;     for (int i(2), _E_(n); i <= _E_; ++i)       scanf( %d , f[0] + i), to[++top] = i, nex[top] = fir[f[0][i]],                              fir[f[0][i]] = top;     top = 0;     dfs(1);     scanf( %d , &m);     for (int j(1), _E_(17); j <= _E_; ++j)       for (int i(1), _E_(n); i <= _E_; ++i) f[j][i] = f[j - 1][f[j - 1][i]];     int t = 0;     for (int i(1), _E_(m); i <= _E_; ++i) {       int x, y, l;       scanf( %d %d , &x, &y);       l = lca(x, y);       a[++t] = (dot){dfl[x], dfl[y]};       a[++t] = (dot){dfl[y], dfl[x]};       mn[x] = deep[mn[x]] > deep[l] ? l : mn[x];       mn[y] = deep[mn[y]] > deep[l] ? l : mn[y];     }     doit(1);     sort(a + 1, a + m + m + 1, cmp);     for (int j(1), _E_(17); j <= _E_; ++j)       for (int i(1), _E_(n); i <= _E_; ++i) nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];     for (int i(1), _E_(m + m); i <= _E_; ++i)       opl = a[i].b, update(rt[a[i - 1].a], rt[a[i].a], 1, n);     for (int i(1), _E_(n); i <= _E_; ++i)       if (!rt[i]) rt[i] = rt[i - 1];     scanf( %d , &q);     for (int i(1), _E_(q); i <= _E_; ++i) {       int u, v;       scanf( %d %d , &u, &v);       if (u == v) {         printf( 0 n );         continue;       }       int L = lca(u, v), ans = 0;       for (int j(17), _E_(0); j >= _E_; --j)         if (deep[nxt[j][u]] > deep[L]) u = nxt[j][u], ans += 1 << j;       for (int j(17), _E_(0); j >= _E_; --j)         if (deep[nxt[j][v]] > deep[L]) v = nxt[j][v], ans += 1 << j;       if (L == u && nxt[0][v])         printf( %d n , ans + 1);       else if (L == v && nxt[0][u])         printf( %d n , ans + 1);       else if (!nxt[0][u] || !nxt[0][v])         printf( -1 n );       else         printf( %d n , ans + 2 - exist(u, v));     }     return 0;   }