#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<vector<long long> > hopp(40, vector<long long>(n)),
      wsum(40, vector<long long>(n)), minw(40, vector<long long>(n));
  for (auto &x : hopp[0]) cin >> x;
  for (auto &x : wsum[0]) cin >> x;
  for (int i = (0); i < int(n); ++i) minw[0][i] = wsum[0][i];
  for (int i = (1); i < int(40); ++i)
    for (int j = (0); j < int(n); ++j) hopp[i][j] = hopp[i - 1][hopp[i - 1][j]];
  for (int i = (1); i < int(40); ++i)
    for (int j = (0); j < int(n); ++j)
      wsum[i][j] = wsum[i - 1][j] + wsum[i - 1][hopp[i - 1][j]];
  for (int i = (1); i < int(40); ++i)
    for (int j = (0); j < int(n); ++j)
      minw[i][j] = min(minw[i - 1][j], minw[i - 1][hopp[i - 1][j]]);
  auto sum = [&](int v, long long l) {
    long long res = 0;
    int i = 0;
    while (l) {
      if (l & 1) {
        res += wsum[i][v];
        v = hopp[i][v];
      }
      l /= 2;
      i++;
    }
    return res;
  };
  auto mn = [&](int v, long long l) {
    long long res = 1e9;
    int i = 0;
    while (l) {
      if (l & 1) {
        res = min(res, minw[i][v]);
        v = hopp[i][v];
      }
      l /= 2;
      i++;
    }
    return res;
  };
  for (int i = (0); i < int(n); ++i)
    cout << sum(i, k) << ' ' << mn(i, k) << endl;
}
