#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
long long dp[maxn][35];
long long sum[maxn][35];
int f[maxn][35];
int n;
long long k;
void init() {
  for (int i = 0; i < maxn - 1; i++) {
    for (int j = 0; j < 35; j++) {
      dp[i][j] = 1e18;
    }
  }
}
void DP() {
  for (long long j = 1; (1LL << j) <= k; j++) {
    for (int i = 0; i < n; i++) {
      int p = f[i][j - 1];
      f[i][j] = f[p][j - 1];
      dp[i][j] = min(dp[i][j], min(dp[i][j - 1], dp[p][j - 1]));
      sum[i][j] += sum[i][j - 1] + sum[p][j - 1];
    }
  }
}
int main() {
  init();
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    f[i][0] = x;
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    dp[i][0] = x;
    sum[i][0] = x;
  }
  DP();
  for (int i = 0; i < n; i++) {
    long long T = k;
    long long ans1 = 1e18;
    long long ans2 = 0;
    int pre = i;
    for (int j = 34; j >= 0; j--) {
      if ((1LL << j) <= T) {
        ans1 = min(ans1, dp[pre][j]);
        ans2 += sum[pre][j];
        pre = f[pre][j];
        T -= (1LL << j);
      }
      if (T == 0) break;
    }
    cout << ans2 << " " << ans1 << endl;
  }
}
