#include <bits/stdc++.h>
using namespace std;
inline int init() {
  int now = 0, ju = 1;
  char c;
  bool flag = false;
  while (1) {
    c = getchar();
    if (c == '-')
      ju = -1;
    else if (c >= '0' && c <= '9') {
      now = now * 10 + c - '0';
      flag = true;
    } else if (flag)
      return now * ju;
  }
}
inline long long llinit() {
  long long now = 0, ju = 1;
  char c;
  bool flag = false;
  while (1) {
    c = getchar();
    if (c == '-')
      ju = -1;
    else if (c >= '0' && c <= '9') {
      now = now * 10 + c - '0';
      flag = true;
    } else if (flag)
      return now * ju;
  }
}
long long k, sum[100005][42], mn[100005][42];
int n, f[100005][42];
void calc() {
  for (int j = 1; j <= 40; j++) {
    for (int i = 0; i < n; i++) {
      f[i][j] = f[f[i][j - 1]][j - 1];
      sum[i][j] = sum[f[i][j - 1]][j - 1] + sum[i][j - 1];
      mn[i][j] = min(mn[f[i][j - 1]][j - 1], mn[i][j - 1]);
    }
  }
}
pair<long long, long long> query(int now) {
  long long ret = 0x7f7f7f7f;
  long long res = 0;
  for (int i = 40; i >= 0; i--) {
    if ((1LL << i) & k) {
      ret = min(ret, mn[now][i]);
      res = res + sum[now][i];
      now = f[now][i];
    }
  }
  return make_pair(res, ret);
}
int main() {
  n = init();
  k = llinit();
  for (int i = 0; i < n; i++) {
    f[i][0] = init();
  }
  for (int i = 0; i < n; i++) {
    sum[i][0] = mn[i][0] = llinit();
  }
  calc();
  pair<long long, long long> tmp;
  for (int i = 0; i < n; i++) {
    tmp = query(i);
    printf("%I64d %I64d\n", tmp.first, tmp.second);
  }
  return 0;
}
