#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e+5 + 100;
const int MAX_PW = 34;
int f[LIM];
int w[LIM];
int _min[LIM][MAX_PW];
long long sum[LIM][MAX_PW];
int to[LIM][MAX_PW];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  long long k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> f[i];
  for (int i = 0; i < n; ++i) cin >> w[i];
  for (int i = 0; i < n; ++i) {
    sum[i][0] = _min[i][0] = w[i];
    to[i][0] = f[i];
  }
  for (int pw = 1; pw < MAX_PW; ++pw) {
    for (int i = 0; i < LIM; ++i) {
      _min[i][pw] = min(_min[i][pw - 1], _min[to[i][pw - 1]][pw - 1]);
      sum[i][pw] = sum[i][pw - 1] + sum[to[i][pw - 1]][pw - 1];
      to[i][pw] = to[to[i][pw - 1]][pw - 1];
    }
  }
  for (int i = 0; i < n; ++i) {
    int min_ans = 1e+9;
    long long sum_ans = 0;
    int cur = i;
    for (int pw = MAX_PW; pw >= 0; --pw)
      if ((k >> pw) & 1) {
        min_ans = min(min_ans, _min[cur][pw]);
        sum_ans += sum[cur][pw];
        cur = to[cur][pw];
      }
    cout << sum_ans << " " << min_ans << '\n';
  }
  return 0;
}
