#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int LOGMAXN = 40;
const int INF = 1e9;
int f[MAXN];
int c[MAXN];
long long s[MAXN][LOGMAXN];
long long mn[MAXN][LOGMAXN];
int p[MAXN][LOGMAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> f[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n; i++) p[i][1] = f[i], s[i][1] = mn[i][1] = c[i];
  for (int i = 2; i <= LOGMAXN; i++)
    for (int j = 0; j < n; j++) {
      p[j][i] = p[p[j][i - 1]][i - 1];
      s[j][i] = s[j][i - 1] + s[p[j][i - 1]][i - 1];
      mn[j][i] = min(mn[j][i - 1], mn[p[j][i - 1]][i - 1]);
    }
  for (int i = 0; i < n; i++) {
    int x = i;
    long long m1 = INF, s1 = 0LL;
    for (int j = LOGMAXN - 1; j >= 0; j--)
      if ((1LL << j) & k) {
        j++;
        s1 += 1LL * s[x][j];
        m1 = min(m1, mn[x][j]);
        x = p[x][j];
        j--;
      }
    cout << s1 << " " << m1 << endl;
  }
  return 0;
}
