#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const long long INF = 0x7fffffffffffffff;
template <typename A, typename B>
ostream &operator<<(ostream &s, const pair<A, B> &p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &c) {
  s << "[ ";
  for (auto it : c) s << it << " ";
  s << "]";
  return s;
}
template <typename T>
ostream &operator<<(ostream &o, const set<T> &st) {
  o << "{";
  for (auto it = st.begin(); it != st.end(); it++)
    o << (it == st.begin() ? "" : ", ") << *it;
  return o << "}";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &make_pair) {
  o << "{";
  for (auto it = make_pair.begin(); it != make_pair.end(); it++) {
    o << (it == make_pair.begin() ? "" : ", ") << it->first << ":"
      << it->second;
  }
  o << "}";
  return o;
}
int n;
long long k;
int mn[100005][40], nxt[100005][40];
long long sum[100005][40];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%d", &nxt[i][0]);
  for (int i = 0; i < n; i++) scanf("%lld", &sum[i][0]), mn[i][0] = sum[i][0];
  for (int i = 1; i < 40; i++) {
    for (int j = 0; j < n; j++) {
      nxt[j][i] = nxt[nxt[j][i - 1]][i - 1];
      sum[j][i] = sum[j][i - 1] + sum[nxt[j][i - 1]][i - 1];
      mn[j][i] = min(mn[j][i - 1], mn[nxt[j][i - 1]][i - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    long long kk = k;
    int m = 1e9;
    long long s = 0;
    int cur = i;
    for (int j = 39; kk; j--)
      if ((1LL << j) <= kk) {
        kk -= (1LL << j);
        s += sum[cur][j];
        m = min(m, mn[cur][j]);
        cur = nxt[cur][j];
      }
    assert(kk == 0);
    printf("%lld %d\n", s, m);
  }
}
