// {{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#define debug(x...)
#define debug_arr(x...)
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// }}}

const int N = 2e5 + 10;
int head[N], e;
struct E
{
    int v, next;
} edge[N << 1];

void addedge(int u, int v)
{
    edge[e].v = v, edge[e].next = head[u];
    head[u] = e++;
}

int st[N], ed[N], dep[N];
int tim;

void dfs(int u, int f, int d)
{
    tim++;
    st[u] = tim;
    dep[u] = d;
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == f) continue;
        dfs(v, u, d + 1);
    }
    tim++;
    ed[u] = tim;
    // debug(u, st[u], ed[u], dep[u]);
}

int n, m;
vi vec[N];

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (cin >> n)
    {
        clr(head, -1), e = 0;
        for (int i = 2; i <= n; ++i)
        {
            int f;
            cin >> f;
            addedge(i, f);
            addedge(f, i);
        }

        tim = 0;
        dfs(1, -1, 0);
        for (int i = 0; i < n; ++i) vec[i].clear();

        for (int i = 1; i <= n; ++i)
        {
            int curd = dep[i];
            vec[curd].push_back(st[i]);
        }
        for (int i = 0; i < n; ++i) sort(all(vec[i]));

        // debug(vec[2]);

        cin >> m;
        for (int i = 1; i <= m; ++i)
        {
            int u, d;
            cin >> u >> d;
            if (d < dep[u])
            {
                cout << 0 << endl;
                continue;
            }

            int l = st[u], r = ed[u];
            // debug(u, l, r);

            auto iter1 = lower_bound(all(vec[d]), l);
            auto iter2 = lower_bound(all(vec[d]), r);

            int cnt = iter2 - iter1;
            cout << cnt << endl;
        }
    }

    return 0;
}
#include <bits/stdc++.h>
using namespace std;

const int M = 2e5;
vector<int> adj[M];
long long c[18], k, memo[18][(1 << 18)];
map<long long, map<long long, long long>> dist;

long long solve(int i, int mask) {
    if (mask == (1 << k) - 1)
        return 0;

    long long &res = memo[i][mask];
    if (res == -1) {
        res = 1e18;
        for (int j = 0; j < k; j++)
            if (!((1 << j) & mask))
                res = min(res, dist[c[i]][c[j]] + solve(j, mask | (1 << j)));
    }
    return res;
}

void bfs(int i) {
    long long d[M] = {};
    bool v[M] = {};
    queue<int> q;
    q.push(i);
    v[i] = 1;

    while (!q.empty()) {
        int cur = q.front();
        q.pop();

        for (int x : adj[cur])
            if (!v[x])
                q.push(x), v[x] = 1, d[x] = d[cur] + 1;
    }
    for (int j = 0; j < k; j++)
        dist[i][c[j]] = dist[c[j]][i] = d[c[j]];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    memset(memo, -1, sizeof memo);
    int n, m;
    cin >> n >> m;
    while (m--) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin >> k;
    for (int i = 0; i < k; i++)
        cin >> c[i], c[i]--;

    for (int i = 0; i < k; i++)
        bfs(c[i]);

    for (int i = 0; i < k - 1; i++)
        for (int j = i + 1; j < k; j++)
            if (!dist[c[i]][c[j]])
                return cout << "-1\n", 0;

    long long ans = 1e18;
    for (int i = 0; i < k; i++)
        ans = min(ans, solve(i, (1 << i)));
    cout << ans + 1 << '\n';
}
