#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long dp1[100005][40], dp2[100005][40], dp3[100005][40];
long long ans1[100005], ans2[100005];
int main() {
  scanf("%lld", &n);
  scanf("%lld", &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &dp1[i][0]);
  }
  for (int i = 0; i < n; i++) {
    ans2[i] = 2e10;
    ans1[i] = 0;
    scanf("%lld", &dp2[i][0]);
    dp3[i][0] = dp2[i][0];
  }
  for (int i = 1; i <= 38; i++) {
    for (int j = 0; j < n; j++) {
      dp1[j][i] = dp1[dp1[j][i - 1]][i - 1];
      dp2[j][i] = dp2[j][i - 1] + dp2[dp1[j][i - 1]][i - 1];
      dp3[j][i] = min(dp3[j][i - 1], dp3[dp1[j][i - 1]][i - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    long long kk = k;
    int u = i;
    for (long long j = 38; j >= 0; j--) {
      if ((kk - ((long long)1 << j)) >= 0) {
        ans1[i] += dp2[u][j];
        ans2[i] = min(ans2[i], dp3[u][j]);
        kk -= ((long long)1 << j);
        u = dp1[u][j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%lld %lld\n", ans1[i], ans2[i]);
  }
  return 0;
}
