#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int L = 20;
struct node {
  int nxt, to;
} bian[2 * N];
struct ques {
  int to, id, lca;
  int has;
  int fir;
};
int n, m, Q;
int que[N][2];
int hd[N], cnt;
int fa[N][22], d[N];
int dfn[N], dfn2[N], tot;
int go[N][22];
int route[N][3];
bool vis[N];
vector<int> rt[N];
vector<ques> q[N];
bool ca[N];
int f[N];
int ans[N];
void ins(int x, int y) {
  bian[++cnt].nxt = hd[x];
  bian[cnt].to = y;
  hd[x] = cnt;
}
void dfs1(int x, int dep) {
  d[x] = dep;
  dfn[x] = ++tot;
  for (int i = hd[x]; i; i = bian[i].nxt) {
    int y = bian[i].to;
    if (y != fa[x][0]) {
      fa[y][0] = x;
      dfs1(y, dep + 1);
    }
  }
  dfn2[x] = tot;
}
void dp(int x) {
  go[x][0] = 0;
  for (int i = 0; i < rt[x].size(); i++) {
    int anc = route[rt[x][i]][2];
    if (d[anc] < d[x]) {
      if ((!go[x][0]) || d[go[x][0]] > d[anc]) go[x][0] = anc;
    }
  }
  for (int i = hd[x]; i; i = bian[i].nxt) {
    int y = bian[i].to;
    if (y != fa[x][0]) {
      dp(y);
      if (go[y][0]) {
        if (d[go[y][0]] < d[x]) {
          if (!go[x][0] || d[go[x][0]] > d[go[y][0]]) go[x][0] = go[y][0];
        }
      }
    }
  }
}
int lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = L; i >= 0; i--)
    if (d[fa[x][i]] >= d[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = L; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void add(int x) {
  for (; x <= n; x += x & (-x)) f[x]++;
}
int query(int x) {
  int sum = 0;
  for (; x; x -= x & (-x)) sum += f[x];
  return sum;
}
void dfs2(int x) {
  vis[x] = 1;
  for (int i = 0; i < q[x].size(); i++) {
    int y = q[x][i].to;
    int zong = query(dfn2[y]) - query(dfn[y] - 1);
    q[x][i].fir = zong;
  }
  for (int i = 0; i < rt[x].size(); i++) {
    int y = (route[rt[x][i]][1] == x) ? route[rt[x][i]][0] : route[rt[x][i]][1];
    add(dfn[y]);
  }
  for (int i = hd[x]; i; i = bian[i].nxt) {
    int y = bian[i].to;
    if (y != fa[x][0]) {
      dfs2(y);
    }
  }
  for (int i = 0; i < q[x].size(); i++) {
    int y = q[x][i].to;
    int now = query(dfn2[y]) - query(dfn[y] - 1);
    if (q[x][i].fir < now) {
      ans[q[x][i].id] = q[x][i].has + 1;
    } else {
      if (ca[q[x][i].id])
        ans[q[x][i].id] = q[x][i].has + 2;
      else
        ans[q[x][i].id] = -1;
    }
  }
}
int main() {
  scanf("%d", &n);
  int t;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &t);
    ins(t, i);
    ins(i, t);
  }
  scanf("%d", &m);
  dfs1(1, 1);
  d[0] = -1;
  for (int j = 1; j <= L; j++)
    for (int i = 1; i <= n; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &route[i][0], &route[i][1]);
    rt[route[i][0]].push_back(i);
    rt[route[i][1]].push_back(i);
    route[i][2] = lca(route[i][1], route[i][0]);
  }
  dp(1);
  for (int j = 1; j <= L; j++)
    for (int i = 1; i <= n; i++) go[i][j] = go[go[i][j - 1]][j - 1];
  scanf("%d", &Q);
  int st, ed;
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d", &st, &ed);
    que[i][0] = st, que[i][1] = ed;
    int anc = lca(st, ed);
    if (anc == st || anc == ed) {
      if (d[st] < d[ed]) swap(st, ed);
      int sum = 0;
      bool fl = false;
      for (int j = L; j >= 0; j--) {
        if (d[go[st][j]] > d[ed]) {
          if (st != go[st][j]) st = go[st][j], sum += 1 << j;
        } else if (go[st][j])
          fl = true;
      }
      if (fl)
        ans[i] = sum + 1;
      else
        ans[i] = -1;
    } else {
      int sst = 0, sed = 0;
      bool cst = false, ced = false;
      for (int j = L; j >= 0; j--) {
        if (d[go[st][j]] > d[anc]) {
          if (st != go[st][j]) st = go[st][j], sst += (1 << j);
        } else if (go[st][j])
          cst = true;
      }
      for (int j = L; j >= 0; j--) {
        if (d[go[ed][j]] > d[anc]) {
          if (ed != go[ed][j]) ed = go[ed][j], sed += (1 << j);
        } else if (go[ed][j])
          ced = true;
      }
      ca[i] = (cst && ced);
      ques nn;
      nn.id = i;
      nn.lca = anc, nn.to = ed;
      nn.has = sed + sst;
      q[st].push_back(nn);
      ques mm = nn;
      mm.to = st;
      q[ed].push_back(mm);
    }
  }
  dfs2(1);
  for (int i = 1; i <= Q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
