#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
long long sm[N][35];
int mn[N][35], go[N][35];
void query(int node, long long k) {
  long long sum;
  int m, p;
  sum = 0;
  m = INT_MAX;
  for (int i = 0; i < 35; i++) {
    if (k & (1ll << i)) {
      sum += sm[node][i];
      m = min(m, mn[node][i]);
      node = go[node][i];
    }
  }
  cout << sum << " " << m << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> go[i][0];
  }
  for (int i = 0; i < n; i++) {
    cin >> sm[i][0];
    mn[i][0] = sm[i][0];
  }
  for (int i = 1; i < 35; i++) {
    for (int j = 0; j < n; j++) {
      go[j][i] = go[go[j][i - 1]][i - 1];
      sm[j][i] = sm[j][i - 1] + sm[go[j][i - 1]][i - 1];
      mn[j][i] = min(mn[j][i - 1], mn[go[j][i - 1]][i - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    query(i, k);
  }
}
