#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
  bool f = 0;
  char c = getchar();
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const int N = 5e4 + 5;
int dfn[N], eit[N], d[N], dd[N], a[N], aa[N], tg[N], T, n, q;
vector<int> g[N];
void dfs(int x) {
  dfn[x] = ++*dfn;
  aa[*dfn] = a[x];
  dd[*dfn] = d[x];
  for (int y : g[x]) d[y] = d[x] + 1, dfs(y);
  eit[x] = *dfn;
}
void doit() {
  int x;
  read(x);
  int l = dfn[x], r = eit[x];
  int ans = 0, cnt = 0;
  for (int i = l; i <= r; i++)
    if (tg[i] <= T) {
      tg[i] = T + aa[i];
      ans += dd[i];
      cnt++;
    }
  write(ans - cnt * d[x]);
  putchar(' ');
  write(cnt);
  puts("");
}
signed main() {
  read(n);
  read(q);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 2, x; i <= n; i++) g[read(x)].push_back(i);
  dfs(1);
  for (T = 1; T <= q; T++) doit();
}
