#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
const long long inf64 = 1ll * inf * inf;
const int LOG = 50;
const int N = 100005;
int f[LOG][N];
int MN[LOG][N];
int n;
long long SUM[LOG][N];
long long k;
bool solve() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> f[0][i];
  }
  for (int i = 0; i < n; i++) {
    cin >> SUM[0][i];
    MN[0][i] = SUM[0][i];
  }
  for (int i = 1; i < LOG; i++) {
    for (int j = 0; j < n; j++) {
      f[i][j] = f[i - 1][f[i - 1][j]];
    }
  }
  for (int i = 1; i < LOG; i++) {
    for (int j = 0; j < n; j++) {
      MN[i][j] = min(MN[i - 1][j], MN[i - 1][f[i - 1][j]]);
      SUM[i][j] = SUM[i - 1][j] + SUM[i - 1][f[i - 1][j]];
    }
  }
  for (int i = 0; i < n; i++) {
    int v = i;
    long long _sum = 0;
    int _min = inf;
    for (int j = 0; j < LOG; j++) {
      if ((1ll << j) & k) {
        _sum += SUM[j][v];
        _min = min(_min, MN[j][v]);
        v = f[j][v];
      }
    }
    cout << _sum << ' ' << _min << '\n';
  }
  return true;
}
int main() {
  solve();
  return 0;
}
