#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}
const int maxn = 2e5 + 5;
int n, m, q, t, idx;
int dep[maxn], pre[maxn][21], low[maxn][21];
int dfn[maxn], lst[maxn], cnt[maxn];
int ans[maxn], mrk[maxn], sum[maxn];
struct node {
  int id, x, y;
  bool operator<(const node &b) const { return x == b.x ? !id : x < b.x; }
} p[maxn * 5];
struct edge {
  int v, nxt;
};
int head[maxn];
vector<edge> e;
void adde(int u, int v) {
  e.push_back((edge){v, head[u]});
  head[u] = e.size() - 1;
}
int mind(int a, int b) { return dep[a] < dep[b] ? a : b; }
void dfs1(int u, int f) {
  dfn[u] = ++idx;
  dep[u] = dep[f] + 1;
  pre[u][0] = f;
  for (int i = (1); i <= (20); ++i) pre[u][i] = pre[pre[u][i - 1]][i - 1];
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs1(v, u);
  }
  lst[u] = idx;
}
void dfs2(int u, int f) {
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs2(v, u);
    low[u][0] = mind(low[u][0], low[v][0]);
  }
}
void dfs3(int u, int f) {
  for (int i = (1); i <= (20); ++i) low[u][i] = low[low[u][i - 1]][i - 1];
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs3(v, u);
  }
}
int find_under(int &u, int v) {
  if (u == v) return 0;
  int res = 0;
  for (int i = (20); i >= (0); --i)
    if (dep[v] < dep[low[u][i]]) {
      res += (1 << i);
      u = low[u][i];
    }
  if (dep[low[u][0]] > dep[v]) u = -1;
  return res;
}
int lca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  for (int i = (20); i >= (0); --i)
    if (dep[a] <= dep[b] - (1 << i)) b = pre[b][i];
  if (a == b) return a;
  for (int i = (20); i >= (0); --i)
    if (pre[a][i] != pre[b][i]) a = pre[a][i], b = pre[b][i];
  return pre[a][0];
}
void insert(int x) {
  x++;
  for (; x < maxn; x += x & -x) sum[x]++;
}
int query(int x) {
  x++;
  int y = 0;
  for (; x; x -= x & -x) y += sum[x];
  return y;
}
void sol() {
  rd(q);
  for (int i = (1); i <= (q); ++i) {
    int u, v;
    rd(u), rd(v);
    int l = lca(u, v);
    ans[i] += find_under(u, l);
    ans[i] += find_under(v, l);
    if (u == -1 || v == -1) {
      ans[i] = -1;
      continue;
    } else if (u == l || v == l) {
      ans[i]++;
      continue;
    }
    mrk[i] = 1;
    if (dfn[u] > dfn[v]) swap(u, v);
    p[++t] = (node){i, lst[u], lst[v]};
    p[++t] = (node){-i, dfn[u] - 1, lst[v]};
    p[++t] = (node){-i, lst[u], dfn[v] - 1};
    p[++t] = (node){i, dfn[u] - 1, dfn[v] - 1};
  }
  sort(p + 1, p + t + 1);
  for (int i = (1); i <= (t); ++i) {
    int id = p[i].id, x = p[i].x, y = p[i].y;
    if (id == 0)
      insert(p[i].y);
    else {
      if (id > 0)
        cnt[id] += query(p[i].y);
      else
        cnt[-id] -= query(p[i].y);
    }
  }
  for (int i = (1); i <= (q); ++i) {
    if (!mrk[i])
      printf("%d\n", ans[i]);
    else {
      if (cnt[i])
        printf("%d\n", ans[i] + 1);
      else
        printf("%d\n", ans[i] + 2);
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  rd(n);
  for (int i = (2); i <= (n); ++i) {
    int u;
    rd(u);
    adde(u, i), adde(i, u);
  }
  dfs1(1, 0);
  dep[0] = n;
  rd(m);
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    rd(u), rd(v);
    int l = lca(u, v);
    if (u != l) low[u][0] = mind(low[u][0], l);
    if (v != l) low[v][0] = mind(low[v][0], l);
    if (dfn[u] > dfn[v]) swap(u, v);
    p[++t] = (node){0, dfn[u], dfn[v]};
  }
  dfs2(1, 0);
  dfs3(1, 0);
  sol();
  return 0;
}
