#include <bits/stdc++.h>
using namespace std;
long long k;
int n;
struct ans {
  long long sum;
  int m;
  int dest;
};
ans a[40][100005];
int main() {
  scanf("%d %lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[0][i].dest);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[0][i].m);
    a[0][i].sum = a[0][i].m;
  }
  for (int i = 1; i <= 39; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j].dest = a[i - 1][a[i - 1][j].dest].dest;
      a[i][j].sum = a[i - 1][j].sum + a[i - 1][a[i - 1][j].dest].sum;
      a[i][j].m = min(a[i - 1][j].m, a[i - 1][a[i - 1][j].dest].m);
    }
  }
  for (int i = 0; i < n; i++) {
    int dest = i;
    long long sum = 0;
    int m = 199999999;
    for (int j = 0; j <= 39; j++) {
      if (!((1LL << j) & k)) continue;
      sum += a[j][dest].sum;
      m = min(m, a[j][dest].m);
      dest = a[j][dest].dest;
    }
    printf("%lld %d\n", sum, m);
  }
  return 0;
}
