Problem: You are given a functional graph. It is a directed graph, in which from each vertex goes exactly one arc. The vertices are numerated from 0 to n - 1.

Graph is given as the array f0, f1, ..., fn - 1, where fi — the number of vertex to which goes the only arc from the vertex i. Besides you are given array with weights of the arcs w0, w1, ..., wn - 1, where wi — the arc weight from i to fi.

<image> The graph from the first sample test.

Also you are given the integer k (the length of the path) and you need to find for each vertex two numbers si and mi, where:

  * si — the sum of the weights of all arcs of the path with length equals to k which starts from the vertex i; 
  * mi — the minimal weight from all arcs on the path with length k which starts from the vertex i. 



The length of the path is the number of arcs on this path.

Input

The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 1010). The second line contains the sequence f0, f1, ..., fn - 1 (0 ≤ fi < n) and the third — the sequence w0, w1, ..., wn - 1 (0 ≤ wi ≤ 108).

Output

Print n lines, the pair of integers si, mi in each line.

Examples

Input

7 3
1 2 3 4 3 2 6
6 3 1 4 2 2 3


Output

10 1
8 1
7 1
10 2
8 2
7 1
9 3


Input

4 4
0 1 2 3
0 1 2 3


Output

0 0
4 1
8 2
12 3


Input

5 3
1 2 3 4 0
4 1 2 14 3


Output

7 1
17 1
19 2
21 3
8 1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
void _r(const int& x) { scanf("%d", &x); }
void _r(const long long& x) { scanf("%I64d", &x); }
void _r(const char* x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(const T& head, const U&... tail) {
  _r(head);
  R(tail...);
}
void _w(const char x) { putchar(x); }
void _w(const char* x) { printf("%s", x); }
void _w(const int x) { printf("%d", x); }
void _w(const long long x) { printf("%I64d", x); }
void _w(const double x) { printf("%.6f", x); }
void W() {}
template <class T, class... U>
void W(const T& head, const U&... tail) {
  _w(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
const long long mod = 1e9 + 7;
long long fp1(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    b >>= 1;
    a *= a;
  }
  return ans;
}
long long fp2(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return ans;
}
long long Read() {
  long long res = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    res = res * 10 + ch - '0';
    ch = getchar();
  }
  return res * flag;
}
const int N = 1e5 + 5;
int to[N][40], mi[N][40];
long long sum[N][40];
int son[N], w[N];
void ST(int n, long long k) {
  for (int i = (1); i <= (n); i++)
    to[i][0] = son[i], sum[i][0] = w[i], mi[i][0] = w[i];
  for (int j = 1; (1LL << j) <= k; j++) {
    for (int i = 1; i <= n; i++) {
      to[i][j] = to[to[i][j - 1]][j - 1];
      sum[i][j] = sum[i][j - 1] + sum[to[i][j - 1]][j - 1];
      mi[i][j] = min(mi[i][j - 1], mi[to[i][j - 1]][j - 1]);
    }
  }
}
long long ans1[N];
int ans2[N], nt[N];
void solve(int n, long long k) {
  memset(ans2, 0x3f3f3f3f, sizeof ans2);
  for (int i = (1); i <= (n); i++) nt[i] = i;
  for (int i = 40; i >= 0; i--) {
    if (k & (1LL << i)) {
      for (int j = (1); j <= (n); j++) {
        ans1[j] += sum[nt[j]][i];
        ans2[j] = min(ans2[j], mi[nt[j]][i]);
        nt[j] = to[nt[j]][i];
      }
    }
  }
}
int main() {
  int n;
  long long k;
  R(n, k);
  for (int i = (1); i <= (n); i++) {
    R(son[i]);
    son[i]++;
  }
  for (int i = (1); i <= (n); i++) R(w[i]);
  ST(n, k);
  solve(n, k);
  for (int i = (1); i <= (n); i++) {
    W(ans1[i], ans2[i]);
  }
  return 0;
}