#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int nxt[N][36];
long long sum[N][36];
int mi[N][36];
int main() {
  int n;
  long long k;
  while (cin >> n >> k) {
    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      nxt[i][0] = x;
    }
    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      sum[i][0] = x;
      mi[i][0] = x;
    }
    for (int j = 1; j <= 35; j++) {
      for (int i = 0; i < n; i++) {
        nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
        mi[i][j] = min(mi[i][j - 1], mi[nxt[i][j - 1]][j - 1]);
        sum[i][j] = sum[i][j - 1] + sum[nxt[i][j - 1]][j - 1];
      }
    }
    for (int i = 0; i < n; i++) {
      long long ans1 = 0;
      int ans2 = 1e9;
      int cur = i;
      for (int j = 0; j <= 35; j++) {
        if (k & ((long long)1 << j)) {
          ans1 += sum[cur][j];
          ans2 = min(ans2, mi[cur][j]);
          cur = nxt[cur][j];
        }
      }
      cout << ans1 << " " << ans2 << endl;
    }
  }
  return 0;
}
