#include <bits/stdc++.h>
using namespace std;
long long sum[100004][35];
long long mi[100004][35];
long long pos[100004][35];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, x, t, m, y, z, k;
  cin >> n >> k;
  vector<long long> dest;
  for (int i = 0; i < n; i++) {
    cin >> pos[i][0];
  }
  for (int i = 0; i < n; i++) {
    cin >> sum[i][0];
    mi[i][0] = sum[i][0];
  }
  for (int j = 1; j < 35; j++) {
    for (int i = 0; i < n; i++) {
      sum[i][j] = sum[i][j - 1] + sum[pos[i][j - 1]][j - 1];
      mi[i][j] = min(mi[i][j - 1], mi[pos[i][j - 1]][j - 1]);
      pos[i][j] = pos[pos[i][j - 1]][j - 1];
    }
  }
  for (int i = 0; i < n; i++) {
    long long curr = i;
    long long sumz = 0;
    long long minz = (1ll << 60) - 1;
    for (int j = 0; j < 35; j++) {
      if ((k >> j) & 1) {
        minz = min(minz, mi[curr][j]);
        sumz += sum[curr][j];
        curr = pos[curr][j];
      }
    }
    cout << sumz << " " << minz << '\n';
  }
  return 0;
}
