#include <bits/stdc++.h>
using namespace std;
struct st {
  long long cur;
  long long len;
  int mini;
  int dest;
};
int n;
long long k;
vector<st> to[100100];
st res[100100];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> res[i].dest;
  for (int i = 0; i < n; i++) cin >> res[i].len;
  for (int i = 0; i < n; i++) {
    res[i].mini = res[i].len;
    res[i].cur = 1LL;
    to[i].push_back(res[i]);
  }
  while (res[0].cur < k) {
    int s = to[0].size() - 1;
    if (res[0].cur + to[0][s].cur > k) {
      for (int i = 0; i < n; i++) to[i].pop_back();
      continue;
    }
    for (int i = 0; i < n; i++) {
      res[i].cur += to[i][s].cur;
      res[i].len += to[res[i].dest][s].len;
      res[i].mini = min(res[i].mini, to[res[i].dest][s].mini);
      res[i].dest = to[res[i].dest][s].dest;
    }
    if (res[0].cur == 2 * to[0][s].cur) {
      for (int i = 0; i < n; i++) to[i].push_back(res[i]);
    }
  }
  for (int i = 0; i < n; i++) cout << res[i].len << " " << res[i].mini << "\n";
  return 0;
}
