#include <bits/stdc++.h>
using namespace std;
int f[44][100050], g[44][100050], n;
long long h[44][100050], K;
int main() {
  scanf("%d%lld", &n, &K);
  int i, x, j;
  for (i = 1; i <= n; i++) {
    scanf("%d", &f[0][i]);
    f[0][i]++;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    g[0][i] = h[0][i] = x;
  }
  for (i = 1; (1ll << i) <= K; i++) {
    for (j = 1; j <= n; j++) {
      f[i][j] = f[i - 1][f[i - 1][j]];
      g[i][j] = min(g[i - 1][j], g[i - 1][f[i - 1][j]]);
      h[i][j] = h[i - 1][j] + h[i - 1][f[i - 1][j]];
    }
  }
  for (i = 1; i <= n; i++) {
    long long t = K;
    int x = i;
    int ans1 = 1 << 30;
    long long ans2 = 0;
    for (j = 0; j <= 40; j++) {
      if (t & (1ll << j)) {
        ans1 = min(ans1, g[j][x]);
        ans2 += h[j][x];
        x = f[j][x];
      }
    }
    printf("%lld %d\n", ans2, ans1);
  }
}
