#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxm = 5e4 + 10;
const int inf = 0x3f3f3f3f;
const int N = 5e4 + 5;
int b[maxm], a[maxm], in[maxm], out[maxm], pt[maxm], dep[maxm], last[maxm];
int tot;
void dfs(vector<vector<int>> &ed, int u, int F) {
  in[u] = ++tot;
  b[in[u]] = a[u];
  dep[in[u]] = dep[in[F]] + 1;
  for (int v : ed[u]) {
    dfs(ed, v, u);
  }
  out[u] = tot;
}
int main() {
  int n, Q;
  cin >> n >> Q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    last[i] = -2 * N;
  }
  vector<vector<int>> ed(n + 1);
  for (int i = 2; i <= n; i++) {
    int F;
    cin >> F;
    ed[F].push_back(i);
  }
  dfs(ed, 1, 0);
  for (int i = 1; i <= Q; i++) {
    int u;
    cin >> u;
    int dis = 0;
    int num = 0;
    for (int j = in[u]; j <= out[u]; j++) {
      int mul = (last[j] + b[j] <= i);
      dis += mul * (dep[j] - dep[in[u]]);
      num += mul;
      last[j] = mul ? i : last[j];
    }
    cout << dis << ' ' << num << endl;
  }
  return 0;
}
