#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
long long n, k;
long long p[N], q[N], sparce_table[N][40], min_[N][40], ans[N][40];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) cin >> q[i];
  for (int i = 0; i < n; i++) {
    sparce_table[i][0] = p[i];
    ans[i][0] = min_[i][0] = q[i];
  }
  for (int i = 1; i < 40; i++) {
    for (int j = 0; j < n; j++) {
      sparce_table[j][i] = sparce_table[sparce_table[j][i - 1]][i - 1];
      ans[j][i] = ans[j][i - 1] + ans[sparce_table[j][i - 1]][i - 1];
      min_[j][i] = min(min_[j][i - 1], min_[sparce_table[j][i - 1]][i - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    int index = i;
    long long counter = 0;
    long long big = 1e18;
    long long rem = k;
    for (int ii = 39; ii >= 0; ii--) {
      if ((1ll << ii) <= rem) {
        rem -= (1ll << ii);
        counter += ans[index][ii];
        big = min(big, min_[index][ii]);
        index = sparce_table[index][ii];
      }
    }
    cout << counter << " " << big << endl;
  }
}
