#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int next, sum, mn;
};
vector<node> operate(vector<node> a, vector<node> b) {
  vector<node> res;
  res.resize(b.size());
  if (a.size() == 0) return b;
  for (long long int i = 0; i < a.size(); i++) {
    res[i].next = a[b[i].next].next;
    res[i].sum = a[b[i].next].sum + b[i].sum;
    res[i].mn = min(a[b[i].next].mn, b[i].mn);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, k;
  cin >> n >> k;
  vector<node> v;
  v.resize(n);
  for (long long int i = 0; i < n; i++) cin >> v[i].next;
  for (long long int i = 0; i < n; i++) cin >> v[i].sum, v[i].mn = v[i].sum;
  vector<node> ans;
  while (k) {
    if (k & 1) ans = operate(ans, v);
    v = operate(v, v);
    k >>= 1;
  }
  for (auto i : ans) cout << i.sum << " " << i.mn << '\n';
}
