#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50005;
int H[MAXN], pre[MAXN], post[MAXN];
vector<int> ch[MAXN];
int pn;
void go(int x) {
  pre[x] = pn++;
  for (int y : ch[x]) {
    H[y] = H[x] + 1;
    go(y);
  }
  post[x] = pn;
}
int SA[MAXN], ST[MAXN], SH[MAXN];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  vector<int> A(n);
  for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
  for (int i = 1; i < n; ++i) {
    int p;
    scanf("%d", &p);
    --p;
    ch[p].push_back(i);
  }
  go(0);
  for (int i = 0; i < n; ++i) {
    SA[pre[i]] = A[i];
    ST[pre[i]] = -100000;
    SH[pre[i]] = H[i];
  }
  for (int qq = 0; qq < q; ++qq) {
    int x;
    scanf("%d", &x);
    --x;
    int st = pre[x], en = post[x];
    int totH = 0, tot = 0;
    for (int i = st; i < en; ++i) {
      int a = SA[i], t = ST[i];
      if (t <= qq) {
        ST[i] = qq + a;
        totH += SH[i];
        ++tot;
      }
    }
    int dist = totH - H[x] * tot;
    printf("%d %d\n", dist, tot);
  }
}
