#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-15;
const double pi = acos(-1.0);
const int inf = 1 << 30;
const long long Mod = 1000000007;
const int N = 1e5 + 5;
const int Log = 50;
long long Sum[N][Log];
long long Min[N][Log];
long long Par[N][Log];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> Par[i][0];
  }
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    Sum[i][0] = Min[i][0] = x;
  }
  for (int j = 1; j < Log; j++) {
    for (int i = 0; i < n; i++) {
      Par[i][j] = Par[Par[i][j - 1]][j - 1];
      Sum[i][j] = Sum[i][j - 1] + Sum[Par[i][j - 1]][j - 1];
      Min[i][j] = min(Min[i][j - 1], Min[Par[i][j - 1]][j - 1]);
    }
  }
  for (long long i = 0; i < n; i++) {
    long long s = 0;
    long long Mn = Mod;
    long long cur = i;
    for (int j = 0; j < Log; j++) {
      if (k & (1LL << j)) {
        Mn = min(Mn, Min[cur][j]);
        s += Sum[cur][j];
        cur = Par[cur][j];
      }
    }
    cout << s << ' ' << Mn << '\n';
  }
  return 0;
}
