#include <bits/stdc++.h>
using namespace std;
const int LOG = 40;
const int MAXN = 101000;
int n;
int p[MAXN];
int w[MAXN];
int go[LOG][MAXN];
long long sm[LOG][MAXN];
long long mn[LOG][MAXN];
long long k;
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", p + i);
  for (int i = 0; i < n; ++i) scanf("%d", w + i);
  for (int i = 0; i < n; ++i) {
    go[0][i] = p[i];
    sm[0][i] = w[i];
    mn[0][i] = w[i];
  }
  for (int i = 1; i < LOG; ++i) {
    for (int j = 0; j < n; ++j) {
      go[i][j] = go[i - 1][go[i - 1][j]];
      sm[i][j] = sm[i - 1][j] + sm[i - 1][go[i - 1][j]];
      mn[i][j] = min(mn[i - 1][j], mn[i - 1][go[i - 1][j]]);
    }
  }
  for (int i = 0; i < n; ++i) {
    long long mni = 1e9;
    long long sum = 0;
    long long nk = k;
    int now = i;
    for (int j = LOG - 1; j >= 0; --j) {
      if ((1ll << j) <= nk) {
        nk -= (1ll << j);
        sum += sm[j][now];
        mni = min(mni, mn[j][now]);
        now = go[j][now];
      }
    }
    printf("%lld %lld\n", sum, mni);
  }
  return 0;
}
