#include<bits/stdc++.h>
using namespace std;
int n, t;
int arr[310];
map<int, int>brr;
int main()
{
cin >> n;
for (int i = 1; i < n; i++)
{
cin >> arr[i];
}
cin >> t;
while (t--)
{
int temp;
cin >> temp;
for (int i = 0; i < temp; i++)
{
int tp;
cin >> tp;
brr[tp]++;
brr[arr[tp]]++;
brr[arr[arr[tp]]]++;
}
int book = 0;
for (auto it = brr.end(); it != brr.begin();)
{
pair<int, int>nd = *(--it);
if (nd.second >= temp)
{
cout << nd.first << endl;
book = 1;
break;
}
}
if (book == 0)cout << 0 << endl;
brr.clear();
}
}