#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int n, m, x, y, f[M], we[M];
long long k, dp[40][M], w[40][M], mn[40][M];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> f[i];
    dp[0][i] = f[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> we[i];
    w[0][i] = we[i];
    mn[0][i] = we[i];
  }
  for (int k = 1; k < 40; k++)
    for (int u = 0; u < n; u++) {
      dp[k][u] = dp[k - 1][dp[k - 1][u]];
      w[k][u] = w[k - 1][u] + w[k - 1][dp[k - 1][u]];
      mn[k][u] = min(mn[k - 1][u], mn[k - 1][dp[k - 1][u]]);
    }
  for (int i = 0; i < n; i++) {
    long long sum = 0, mnn = 2e18, t = i;
    for (int j = 0; j < 40; j++) {
      if (k & (1LL << j)) {
        sum += w[j][t];
        mnn = min(mnn, mn[j][t]);
        t = dp[j][t];
      }
    }
    cout << sum << " " << mnn << endl;
  }
  return 0;
}
