#include <bits/stdc++.h>
using namespace std;
int n;
long long k;
int mi[100007];
int dp[40][100007];
long long sum[40][100007];
int mini[40][100007];
long long si[100007];
void func() {
  for (int i = 1; i < 40; i++)
    for (int j = 0; j < n; j++) dp[i][j] = dp[i - 1][dp[i - 1][j]];
  for (int i = 1; i < 40; i++)
    for (int j = 0; j < n; j++) {
      sum[i][j] = sum[i - 1][j] + sum[i - 1][dp[i - 1][j]];
      mini[i][j] = min(mini[i - 1][j], mini[i - 1][dp[i - 1][j]]);
    }
  for (int i = 0; i < n; i++) {
    mi[i] = INT_MAX;
    long long temp = k;
    int j = i;
    while (temp) {
      long long t = log2(temp);
      si[i] += sum[t][j];
      mi[i] = min(mi[i], mini[t][j]);
      j = dp[t][j];
      temp -= (1LL << t);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0, f; i < n; i++) {
    cin >> f;
    dp[0][i] = f;
  }
  for (int i = 0, w; i < n; i++) {
    cin >> w;
    sum[0][i] = w;
    mini[0][i] = w;
  }
  func();
  for (int i = 0; i < n; i++) cout << si[i] << " " << mi[i] << endl;
  return 0;
}
