#include <bits/stdc++.h>
using namespace std;
template <typename _Tp>
inline _Tp read(_Tp& x) {
  char c11 = getchar(), ob = 0;
  x = 0;
  while (c11 ^ '-' && !isdigit(c11)) c11 = getchar();
  if (c11 == '-') c11 = getchar(), ob = 1;
  while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
  if (ob) x = -x;
  return x;
}
void file(void) {}
int n, head[200005], cnt, in[200005], out[200005], idx, tree[200005],
    fa[200005][22], dep[200005], h[200005][22], m, q, ans[200005], cc[200005];
vector<pair<int, int> > vec[200005];
void change(int a, int x) {
  for (int i = a; i <= n; i += (i & (-i))) tree[i] += x;
}
int query(int a) {
  int ret = 0;
  for (int i = a; i >= 1; i -= (i & (-i))) ret += tree[i];
  return ret;
}
struct edge {
  int to, next;
} e[400005];
vector<int> to[200005];
void add(int a, int b) {
  e[cnt].to = b;
  e[cnt].next = head[a];
  head[a] = cnt++;
}
void dfs(int u, int pre) {
  dep[u] = dep[pre] + 1;
  fa[u][0] = pre;
  in[u] = ++idx;
  for (int i = 1; i <= 20; ++i) {
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
  }
  for (int i = head[u]; i; i = e[i].next) {
    if (e[i].to == pre) continue;
    dfs(e[i].to, u);
  }
  out[u] = idx;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20; i >= 0; --i) {
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  }
  if (x == y) return x;
  for (int i = 20; i >= 0; --i) {
    if (fa[x][i] != fa[y][i]) {
      x = fa[x][i];
      y = fa[y][i];
    }
  }
  return fa[x][0];
}
void update(int x, int v) {
  if (dep[h[x][0]] > dep[v]) h[x][0] = v;
}
void calc(int u, int pre) {
  for (int i = head[u]; i; i = e[i].next) {
    if (e[i].to == pre) continue;
    calc(e[i].to, u);
    update(u, h[e[i].to][0]);
  }
}
int gao(int u, int t, int id) {
  for (int i = 20; i >= 0; --i) {
    if (i >= 1 && (h[u][i] == h[u][i - 1])) continue;
    if (dep[h[u][i]] > dep[t]) {
      u = h[u][i];
      ans[id] += (1 << i);
    }
  }
  return u;
}
void getans(int u, int pre) {
  for (int i = 0; i < vec[u].size(); ++i) {
    int t = vec[u][i].first, y = vec[u][i].second;
    cc[y] = query(out[t]) - query(in[t] - 1);
  }
  for (int i = 0; i < to[u].size(); ++i) {
    int t = to[u][i];
    change(in[t], 1);
  }
  for (int i = head[u]; i; i = e[i].next) {
    if (e[i].to == pre) continue;
    getans(e[i].to, u);
  }
  for (int i = 0; i < vec[u].size(); ++i) {
    int t = vec[u][i].first, y = vec[u][i].second;
    if (cc[y] != query(out[t]) - query(in[t] - 1)) ans[y]--;
  }
}
int main() {
  cnt = 1;
  idx = 0;
  read(n);
  for (int i = 2; i <= n; ++i) {
    int x;
    read(x);
    add(x, i);
    add(i, x);
  }
  for (int i = 1; i <= n; ++i) h[i][0] = i;
  dfs(1, 0);
  read(m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    read(x);
    read(y);
    int xy = lca(x, y);
    update(x, xy);
    update(y, xy);
    to[x].push_back(y);
    to[y].push_back(x);
  }
  calc(1, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= 20; ++j) {
      h[i][j] = h[h[i][j - 1]][j - 1];
    }
  }
  read(q);
  for (int i = 1; i <= q; ++i) {
    int x, y;
    read(x);
    read(y);
    if (h[x][20] != h[y][20]) {
      ans[i] = -1;
      continue;
    }
    int xy = lca(x, y);
    x = gao(x, xy, i);
    y = gao(y, xy, i);
    if (x == xy || y == xy)
      ans[i]++;
    else {
      ans[i] += 2;
      vec[x].push_back(make_pair(y, i));
    }
  }
  getans(1, 0);
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
}
