#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
const double eps = 1e-9;
const long long inf = 1e18;
long long to[mx][40], par[mx];
long long mn[mx][40], sum[mx][40], w[mx], a[mx];
int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", w + i);
  }
  for (int i = 0; i < n; i++) {
    sum[i][0] = w[i];
    mn[i][0] = w[i];
    to[i][0] = a[i];
  }
  for (int lg = 1; lg < 35; lg++) {
    for (int i = 0; i < n; i++) {
      to[i][lg] = to[to[i][lg - 1]][lg - 1];
      sum[i][lg] = sum[i][lg - 1] + sum[to[i][lg - 1]][lg - 1];
      mn[i][lg] = min(mn[i][lg - 1], mn[to[i][lg - 1]][lg - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    int ii = i;
    long long sumans = 0, mnn = inf;
    for (int lg = 0; lg < 35; lg++) {
      if (k & (1ll << lg)) {
        mnn = min(mnn, 1ll * mn[ii][lg]);
        sumans += sum[ii][lg];
        ii = to[ii][lg];
      }
    }
    printf("%lld %lld\n", sumans, mnn);
  }
}
