#include <bits/stdc++.h>
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
using namespace std;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
int a[50005];
int adj[50005][5];
int sz[50005];
int last[50005];
int dist[50005];
int depth[50005];
int tin[50005], tout[50005], arr[50005], T = 0;
int st[50005], cost[50005];
bool vis[50005];
void dfs(int u, int d) {
  tin[u] = ++T;
  arr[T] = u;
  cost[tin[u]] = a[u];
  depth[tin[u]] = d;
  bool ok = a[u] == 1;
  for (int i = 0; i < sz[u]; i++) {
    int v = adj[u][i];
    dfs(v, d + 1);
  }
  tout[u] = T;
}
int par[50005];
int ansx[50005], ansy[50005], u[50005];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    last[i] = -200000;
  }
  for (int i = 2; i <= n; i++) {
    int v;
    scanf("%d", &v);
    par[i] = v;
    adj[v][sz[v]] = i;
    sz[v]++;
  }
  dfs(1, 0);
  int x, ans1 = 0, ans2 = 0;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &x);
    ans1 = 0, ans2 = 0;
    int ans1 = 0, ans2 = 0;
    for (int j = tin[x]; j <= tout[x]; j++) {
      int add = (last[j] + cost[j] <= i);
      ans1 += add;
      ans2 += add * depth[j];
      last[j] = add ? i : last[j];
    }
    ansx[i] = ans2 - ans1 * depth[tin[x]];
    ansy[i] = ans1;
    printf("%d %d\n", ansx[i], ansy[i]);
  }
}
