#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T bpow(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
const double eps = 1e-9;
int ts, kk = 1;
int n, mx;
long long int p[3][40][100005], m, q;
int main() {
  int i, j, k, t;
  memset(p, -1, sizeof(p));
  scanf("%d%lld", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &k);
    p[0][0][i] = k;
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &k);
    p[1][0][i] = k;
    p[2][0][i] = k;
  }
  for (i = 1; (1LL << i) <= m; i++) {
    for (j = 0; j < n; j++)
      if (p[0][i - 1][j] != -1) {
        k = p[0][i - 1][j];
        p[0][i][j] = p[0][i - 1][k];
        p[1][i][j] = p[1][i - 1][j] + p[1][i - 1][k];
        p[2][i][j] = min(p[2][i - 1][j], p[2][i - 1][k]);
      }
  }
  mx = i - 1;
  for (j = 0; j < n; j++) {
    q = m;
    long long int r1, r2;
    r1 = 0;
    r2 = (LLONG_MAX / 10LL);
    k = j;
    for (i = mx; i > -1; i--) {
      if ((1LL << i) <= q) {
        q -= (1LL << i);
        r1 += p[1][i][k];
        r2 = min(r2, p[2][i][k]);
        k = p[0][i][k];
      }
    }
    printf("%lld %lld\n", r1, r2);
  }
  return 0;
}
