#include <bits/stdc++.h>
using namespace std;
const int MAX1 = 1e5 + 1, MAX2 = 34;
int n, v[MAX1][MAX2], m[MAX1][MAX2], anm, now;
long long k, s[MAX1][MAX2], ans;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> v[i][0];
  for (int i = 0; i < n; ++i) cin >> s[i][0], m[i][0] = s[i][0];
  for (int j = 1; j < MAX2; ++j)
    for (int i = 0; i < n; ++i) {
      v[i][j] = v[v[i][j - 1]][j - 1];
      s[i][j] = s[i][j - 1] + s[v[i][j - 1]][j - 1];
      m[i][j] = min(m[i][j - 1], m[v[i][j - 1]][j - 1]);
    }
  for (int i = 0; i < n; ++i) {
    ans = 0, anm = 1e9, now = i;
    for (int j = MAX2 - 1; j >= 0; --j)
      if ((k >> j) & 1) {
        ans += s[now][j];
        anm = min(anm, m[now][j]);
        now = v[now][j];
      }
    cout << ans << " " << anm << endl;
  }
  return 0;
}
