//#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//.find_by_order(1); по индексу
//.order_of_key(1);

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve();

int32_t main() {
#ifdef LOCAL
    freopen("Input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}

constexpr int MAXN = 3e5 + 1;
constexpr ll INF = 1e18;

vector<pair<int, int>> graph[MAXN];
int h[MAXN], s[MAXN], p[MAXN];
int tin[MAXN];
int timer = 0;

void dfs(int v, int pr) {
    tin[v] = timer++;
    for (auto [w, u]: graph[v]) {
        if (u == pr)continue;
        dfs(u, v);
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    for (int i = 1; i < n; ++i) {
        graph[p[i]].emplace_back(s[i], i);
    }
    for (int i = 0; i < n; ++i) {
        sort(graph[i].begin(), graph[i].end());
    }
    dfs(0, 0);
    while (q--) {
        int v;
        cin >> v;
        v--;
        cout << tin[v] << '\n';
    }
}