#include <bits/stdc++.h>
using namespace std;
const int N = 100005 + 10;
long long fa[N][36];
long long son[N][36];
long long minn[N][36];
long long n, k;
void sovle(long long u) {
  long long ans = 0, Min = 1e18;
  long long K = k;
  for (long long i = 35; i >= 0; i--) {
    if ((1ll << i) <= K) {
      ans += fa[u][i];
      Min = min(Min, minn[u][i]);
      u = son[u][i];
      K -= (1ll << i);
    }
  }
  printf("%lld %lld\n", ans, Min);
}
signed main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 0; i < n; i++) scanf("%lld", &son[i][0]);
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &fa[i][0]);
    minn[i][0] = fa[i][0];
  }
  for (long long j = 1; j <= 35; j++) {
    for (long long i = 0; i < n; i++) {
      son[i][j] = son[son[i][j - 1]][j - 1];
      fa[i][j] = fa[i][j - 1] + fa[son[i][j - 1]][j - 1];
      minn[i][j] = min(minn[i][j - 1], minn[son[i][j - 1]][j - 1]);
    }
  }
  for (long long i = 0; i < n; i++) {
    sovle(i);
  }
  return 0;
}
