#include <bits/stdc++.h>
constexpr int L = 5e4;
int t[L], p[L], a[L], entrada[L], salida[L], auxiliar[L], d[L];
std::vector<int> e[L];
int ahora;
void dfs(int unico) {
  entrada[unico] = ahora++;
  d[entrada[unico]] = a[unico];
  for (auto v : e[unico]) {
    auxiliar[ahora] = auxiliar[entrada[unico]] + 1;
    dfs(v);
  }
  salida[unico] = ahora;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  p[0] = -1;
  for (int i = 1; i < n; ++i) {
    std::cin >> p[i];
    --p[i];
    e[p[i]].push_back(i);
  }
  dfs(0);
  for (int i = 0; i < q; ++i) {
    int contador = 0, suma = 0;
    int x;
    std::cin >> x;
    --x;
    for (int j = entrada[x]; j < salida[x]; ++j) {
      if (t[j] <= i) {
        ++contador;
        suma += auxiliar[j];
        t[j] = i + d[j];
      }
    }
    std::cout << suma - contador * auxiliar[entrada[x]] << " " << contador
              << "\n";
  }
  return 0;
}
