#include <bits/stdc++.h>
using namespace std;
const int nmax = 100001, logmax = 35;
int n, f[logmax][nmax], r[logmax][nmax];
long long s[logmax][nmax], k;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> f[0][i];
  for (int i = 0; i < n; i++) cin >> r[0][i], s[0][i] = r[0][i];
  for (int i = 1; i < logmax; i++)
    for (int j = 0; j < n; j++) {
      f[i][j] = f[i - 1][f[i - 1][j]];
      r[i][j] = min(r[i - 1][j], r[i - 1][f[i - 1][j]]);
      s[i][j] = s[i - 1][j] + s[i - 1][f[i - 1][j]];
    }
  for (int ii = 0; ii < n; ii++) {
    long long L = 0;
    int R = 1000000000;
    int x = ii;
    for (int i = 0; i < logmax; i++)
      if ((k >> i) & 1) {
        L += s[i][x];
        R = min(R, r[i][x]);
        x = f[i][x];
      }
    cout << L << " " << R << endl;
  }
}
