#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
const int MAXLOGK = 36;
int N;
long long K;
int F[MAXN][MAXLOGK];
long long W[MAXN][MAXLOGK];
long long sum[MAXN][MAXLOGK];
int cur[MAXN];
long long ans[MAXN][2];
int main() {
  ios::sync_with_stdio(0);
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> F[i][0];
  for (int i = 0; i < N; i++) {
    cin >> W[i][0];
    sum[i][0] = W[i][0];
  }
  for (int j = 1; j < MAXLOGK; j++)
    for (int i = 0; i < N; i++) {
      F[i][j] = F[F[i][j - 1]][j - 1];
      W[i][j] = min(W[i][j - 1], W[F[i][j - 1]][j - 1]);
      sum[i][j] = sum[i][j - 1] + sum[F[i][j - 1]][j - 1];
    }
  for (int i = 0; i < N; i++) cur[i] = i, ans[i][1] = 1 << 30;
  for (int j = MAXLOGK - 1; j >= 0; j--)
    if ((K & (1LL << j)))
      for (int i = 0; i < N; i++) {
        ans[i][0] += sum[cur[i]][j];
        ans[i][1] = min(ans[i][1], W[cur[i]][j]);
        cur[i] = F[cur[i]][j];
      }
  for (int i = 0; i < N; i++) cout << ans[i][0] << " " << ans[i][1] << "\n";
  return 0;
}
