#include <bits/stdc++.h>
using namespace std;
long long fa[51][200007], sum[51][200007], mn[51][200007];
inline long long read() {
  long long x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * flag;
}
signed main() {
  long long n = read(), k = read();
  for (long long i = 0; i <= n - 1; ++i) fa[0][i] = read();
  for (long long i = 0; i <= n - 1; ++i) {
    long long x = read();
    sum[0][i] = x;
    mn[0][i] = x;
  }
  for (long long i = 1; i <= 50; ++i) {
    for (long long j = 0; j <= n - 1; ++j) {
      fa[i][j] = fa[i - 1][fa[i - 1][j]];
      sum[i][j] = sum[i - 1][j] + sum[i - 1][fa[i - 1][j]];
      mn[i][j] = min(mn[i - 1][j], mn[i - 1][fa[i - 1][j]]);
    }
  }
  for (long long i = 0; i <= n - 1; ++i) {
    long long res = 0, minn = mn[0][i], p = i;
    for (long long j = 0; j <= 51; ++j) {
      if (k & (1LL << j)) {
        res += sum[j][p];
        minn = min(minn, mn[j][p]);
        p = fa[j][p];
      }
    }
    printf("%lld %lld\n", res, minn);
  }
  return 0;
}
