#include <bits/stdc++.h>
using namespace std;
int n, h[200020], grand[200020][19], from, to, c[200020], t, size[200020],
    up[200020][19], tmp[200020], ans[200020];
vector<int> v[200020];
vector<pair<int, int> > g[200020];
int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x;
}
struct xx {
  int next, to;
} way[200020];
int num, head[200020], dfn[200020];
void add(int from, int to) {
  way[++num].next = head[from];
  way[num].to = to;
  head[from] = num;
}
void dfs(int x) {
  dfn[x] = ++t;
  size[x] = 1;
  h[x] = h[grand[x][0]] + 1;
  for (int j = 1; j <= 17; j++) grand[x][j] = grand[grand[x][j - 1]][j - 1];
  for (int i = head[x]; i; i = way[i].next) {
    int y = way[i].to;
    dfs(y);
    size[x] += size[y];
  }
}
int lcaa(int x, int y) {
  if (h[x] > h[y]) swap(x, y);
  for (int j = 17; j >= 0; j--)
    if (h[grand[y][j]] >= h[x]) y = grand[y][j];
  if (x == y) return x;
  for (int j = 17; j >= 0; j--) {
    if (grand[x][j] != grand[y][j]) {
      x = grand[x][j];
      y = grand[y][j];
    }
  }
  return grand[x][0];
}
void pre() {
  for (int i = n; i >= 1; --i) {
    up[i][0] = i;
    for (int j = head[i]; j; j = way[j].next) {
      int y = way[j].to;
      if (h[up[i][0]] > h[up[y][0]]) up[i][0] = up[y][0];
    }
    for (int j = 0; j < (int)v[i].size(); ++j) {
      int y = lcaa(v[i][j], i);
      if (h[y] < h[up[i][0]]) up[i][0] = y;
    }
  }
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= n; i++) up[i][j] = up[up[i][j - 1]][j - 1];
}
void add(int x) {
  for (; x <= n; x += x & -x) c[x]++;
}
int ask(int x) {
  int y = 0;
  for (; x; x -= x & -x) y += c[x];
  return y;
}
void work(int x) {
  for (int i = 0; i < (int)g[x].size(); i++)
    tmp[g[x][i].second] = ask(dfn[g[x][i].first] + size[g[x][i].first] - 1) -
                          ask(dfn[g[x][i].first] - 1);
  for (int i = 0; i < (int)v[x].size(); i++) add(dfn[v[x][i]]);
  for (int i = head[x]; i; i = way[i].next) work(way[i].to);
  for (int i = 0; i < (int)g[x].size(); i++) {
    if ((ask(dfn[g[x][i].first] + size[g[x][i].first] - 1) -
         ask(dfn[g[x][i].first] - 1)) == tmp[g[x][i].second])
      ans[g[x][i].second]++;
  }
}
int main() {
  n = read();
  for (int i = 2; i <= n; i++) {
    grand[i][0] = read();
    add(grand[i][0], i);
  }
  int m = read();
  for (int i = 1; i <= m; i++) {
    from = read();
    to = read();
    v[from].push_back(to);
    v[to].push_back(from);
  }
  dfs(1);
  pre();
  int q = read();
  for (int i = 1; i <= q; i++) {
    int x = read();
    int y = read();
    int lca = lcaa(x, y);
    for (int j = 17; j >= 0; j--) {
      if (h[up[x][j]] > h[lca]) x = up[x][j], ans[i] += (1 << j);
      if (h[up[y][j]] > h[lca]) y = up[y][j], ans[i] += (1 << j);
    }
    if (h[up[x][0]] > h[lca] || h[up[y][0]] > h[lca]) {
      ans[i] = -1;
      continue;
    }
    ans[i]++;
    if (x != lca && y != lca) g[x].push_back(make_pair(y, i));
  }
  work(1);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
