#include <bits/stdc++.h>
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
const int MAXN = 50505;
int n, q, a[MAXN], fa[MAXN], dfn[MAXN], sz[MAXN], dep[MAXN], dfsClock,
    mat[MAXN], re[MAXN];
vector<int> son[MAXN];
void dfs(int v, int depth) {
  sz[v] = 1;
  dfn[v] = ++dfsClock;
  dep[dfsClock] = depth;
  re[dfsClock] = a[v];
  for (auto g : son[v]) {
    dfs(g, depth + 1);
    sz[v] += sz[g];
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &fa[i]);
    son[fa[i]].push_back(i);
  }
  dfs(1, 1);
  for (int ct = 1; ct <= q; ++ct) {
    int x, l, r, ans = 0, cnt = 0, o = 0;
    scanf("%d", &x);
    o = l = dfn[x], r = l + sz[x];
    while (l < r) {
      if (mat[l] <= ct) mat[l] = ct + re[l], ans += dep[l] - dep[o], ++cnt;
      l++;
    }
    if (l == r) {
      printf("%d %d\n", ans, cnt);
      continue;
    } else
      assert(false);
  }
  return 0;
}
