#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
const long long MAXN = 5e4 + 10;
const long long INF = 1e9;
const long long mod = 1e9 + 7;
const long double eps = 1e-5;
using namespace std;
int n, q;
int a[MAXN];
vector<int> g[MAXN];
int d[MAXN];
int aa[11][MAXN];
int sz[11];
int p[11][MAXN];
int x[11][MAXN];
pair<int, int> t[MAXN][11];
void dfs(int v) {
  t[v][d[v]] = {sz[d[v]], sz[d[v]]};
  p[d[v]][sz[d[v]]] = v;
  sz[d[v]]++;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    d[to] = d[v] + 1;
    dfs(to);
    for (int i = d[v] + 1; i <= 10; i++) {
      t[v][i] = {t[v][i].first == -1
                     ? t[to][i].first
                     : min(t[v][i].first,
                           t[to][i].first == -1 ? ((int)1e9) : t[to][i].first),
                 t[v][i].second == -1 ? t[to][i].second
                                      : max(t[v][i].second, t[to][i].second)};
    }
  }
}
void solve(int tt) {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    g[p].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 10; j++) t[i][j] = {-1, -1};
  dfs(1);
  for (int i = 0; i <= 10; i++)
    for (int j = 0; j < sz[i]; j++) aa[i][j] = a[p[i][j]];
  for (int y = 1; y <= q; y++) {
    int v;
    cin >> v;
    int ans = 0;
    int sum = 0;
    for (int i = d[v]; i <= 10; i++) {
      int cnt = 0;
      for (int j = t[v][i].first; j > -1 && j <= t[v][i].second; j++) {
        if (!x[i][j] || y - x[i][j] >= aa[i][j]) {
          x[i][j] = y;
          cnt++;
        }
      }
      sum += cnt;
      ans += (i - d[v]) * cnt;
    }
    cout << ans << " " << sum << "\n";
  }
}
int main() {
  srand(time(NULL));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  for (int i = 0; i < t; i++) solve(i + 1);
  return 0;
}
