#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 200000 + 5;
int n, q, a[maxn], last[maxn];
vector<int> edge[maxn];
int tot, dep[maxn], nxt[maxn], L[maxn], R[maxn];
void dfs(int u, int f, int d) {
  L[u] = ++tot;
  nxt[tot] = a[u];
  dep[tot] = d;
  for (int v : edge[u]) {
    if (v == f) continue;
    dfs(v, u, d + 1);
  }
  R[u] = tot;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 2, f; i <= n; i++) {
    scanf("%d", &f);
    edge[f].push_back(i);
    edge[i].push_back(f);
  }
  dfs(1, 0, 1);
  for (int t = 1; t <= q; t++) {
    int x;
    scanf("%d", &x);
    int cnt = 0, sum = 0, D = dep[L[x]];
    for (int i = L[x]; i <= R[x]; i++) {
      if (last[i] <= t) {
        cnt++;
        sum += dep[i] - D;
        last[i] = t + nxt[i];
      }
    }
    printf("%d %d\n", sum, cnt);
  }
  return 0;
}
