#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 100, P = 1e9 + 7, INF = 2e9 + 100;
const double ESP = 1. / 10000000000.;
struct aaa {
  long long p, val, minl;
  aaa() { p = val = minl = 0; }
};
aaa spr[36][N];
long long n, k, a;
void build() {
  for (int i = 1; i <= 35; i++) {
    for (int j = 1; j <= n; j++) {
      spr[i][j].p = spr[i - 1][spr[i - 1][j].p].p;
      spr[i][j].val = spr[i - 1][spr[i - 1][j].p].val + spr[i - 1][j].val;
      spr[i][j].minl =
          min(spr[i - 1][j].minl, spr[i - 1][spr[i - 1][j].p].minl);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    spr[0][i].p = a + 1;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a;
    spr[0][i].val = a;
    spr[0][i].minl = a;
  }
  build();
  for (int i = 1; i <= n; i++) {
    long long kk = k;
    long long v = i;
    long long minl = INF;
    long long sum = 0;
    for (int j = 35; j >= 0; j--) {
      if (kk - ((long long)1 << (long long)j) >= 0) {
        minl = min(minl, spr[j][v].minl);
        sum += spr[j][v].val;
        v = spr[j][v].p;
        kk -= ((long long)1 << (long long)j);
      }
    }
    cout << sum << ' ' << minl << endl;
  }
}
