#include <bits/stdc++.h>
using namespace std;
struct node {
  int to;
  long long sumW;
  int minW;
};
vector<node> mul(const vector<node>& a, const vector<node>& b) {
  int n = a.size();
  vector<node> ans(n);
  for (int i = 0; i < n; ++i) {
    ans[i].to = b[a[i].to].to;
    ans[i].sumW = a[i].sumW + b[a[i].to].sumW;
    ans[i].minW = min(a[i].minW, b[a[i].to].minW);
  }
  return ans;
}
int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<node> f(n);
  for (int i = 0; i < n; ++i) cin >> f[i].to;
  for (int i = 0; i < n; ++i) {
    int w;
    cin >> w;
    f[i].sumW = f[i].minW = w;
  }
  vector<node> ans = f;
  k--;
  while (k) {
    if (k & 1) ans = mul(ans, f);
    f = mul(f, f);
    k >>= 1;
  }
  for (int i = 0; i < n; ++i) cout << ans[i].sumW << " " << ans[i].minW << endl;
  return 0;
}
