#include <bits/stdc++.h>

using namespace std;
#define int long long
using pii = pair<int, int>;
using ll = long long;

int inf = 1e18;

void solve(){
    int n, q;
    cin >> n >> q;

    vector <int> in(n);
    vector <int> del;
    for (int i = 2; i <= n; i++){
        int v;
        cin >> v;
        if (v == 1){
            in[i] = 1;
            del.push_back(i);
        }
        else{
            in[i] = in[v];
        }
    }

    for (int i = 0; i < q; i++){
        int v;
        cin >> v;
        if (v == del[0]){
            cout << del[1] << '\n';
        }
        else{
            cout << del[0] << '\n';
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}
