#include <bits/stdc++.h>
using namespace std;
int n;
long long k, sum[100009][49], mn[100009][49];
int nxt[100009][49];
pair<long long, long long> ch(long long x) {
  pair<long long, long long> ret;
  ret.first = 1e9;
  for (long long j = 1, i = 0; j <= k; j *= 2, i++) {
    if (j & k) {
      ret.first = min(ret.first, mn[x][i]);
      ret.second += sum[x][i];
      x = nxt[x][i];
    }
  }
  return ret;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> nxt[i][0];
  for (int i = 0; i < n; i++) {
    cin >> sum[i][0];
    mn[i][0] = sum[i][0];
  }
  for (int j = 1; j < 34; j++) {
    for (int i = 0; i < n; i++) {
      nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
      sum[i][j] = sum[i][j - 1] + sum[nxt[i][j - 1]][j - 1];
      mn[i][j] = min(mn[i][j - 1], mn[nxt[i][j - 1]][j - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    pair<long long, long long> p = ch(i);
    cout << p.second << " " << p.first << "\n";
  }
}
