#include <bits/stdc++.h>
using namespace std;
const int N = 50000;
vector<vector<int> > adj(N);
vector<int> start(N);
vector<int> ending(N);
vector<int> order(N);
vector<int> depth(N);
int counter = 0;
void dfs(int v, int d) {
  depth[counter] = d;
  order[counter] = v;
  start[v] = counter;
  counter++;
  for (auto &u : adj[v]) {
    dfs(u, d + 1);
  }
  ending[v] = counter - 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int n, q;
  cin >> n >> q;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    a--;
    adj[a].push_back(i + 1);
  }
  dfs(0, 0);
  vector<int> last(n);
  vector<int> dur(n);
  for (int i = 0; i < n; i++) {
    last[i] = -A[order[i]];
    dur[i] = A[order[i]];
  }
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    int count = 0;
    int sum = 0;
    int second = start[x - 1];
    int e = ending[x - 1];
    for (int j = second; j <= e; j++) {
      int cond = (last[j] + dur[j] <= i);
      last[j] += cond * (i - last[j]);
      sum += cond * (depth[j] - depth[second]);
      count += cond;
    }
    cout << sum << " " << count << endl;
  }
}
