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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 998244353;
const int INF = (ll)1e9 + 7;
const ll INFLL = (ll)1e18;
template <class t>
using vvector = vector<vector<t>>;
template <class t>
using vvvector = vector<vector<vector<t>>>;
template <class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template <class t, class u>
bool chmax(t &a, u b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class t, class u>
bool chmin(t &a, u b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
namespace templates {
ll modpow(ll x, ll b, ll mod = MOD) {
  ll res = 1;
  while (b) {
    if (b & 1) res = res * x % mod;
    x = x * x % mod;
    b >>= 1;
  }
  return res;
}
ll modinv(ll x) { return modpow(x, MOD - 2); }
bool was_output = false;
template <class t>
void output(t a) {
  if (was_output) cout << " ";
  cout << a;
  was_output = true;
}
void outendl() {
  was_output = false;
  cout << endl;
}
ll in() {
  ll res;
  cin >> res;
  return res;
}
template <class t>
istream &operator>>(istream &is, vector<t> &x) {
  for (auto &i : x) is >> i;
  return is;
}
template <class t, class u>
istream &operator>>(istream &is, pair<t, u> &x) {
  is >> x.first >> x.second;
  return is;
}
template <class t>
t in() {
  t res;
  cin >> res;
  return res;
}
template <class t>
void out(t x) {
  cout << x;
}
template <class t>
vector<t> sorted(
    vector<t> line,
    function<bool(t, t)> comp = [](t a, t b) { return a < b; }) {
  sort(line.begin(), line.end(), comp);
  return line;
}
template <class t>
vector<t> reversed(vector<t> line) {
  reverse(line.begin(), line.end());
  return line;
}
}  // namespace templates
using namespace templates;
void func() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n = in();
  ll k = in();
  vector<int> nexts(n);
  vector<ll> weights(n);
  for (auto &i : (nexts)) i = in();
  for (auto &i : (weights)) i = in();
  vvector<pll> mins_dp(n, vector<pll>(40, {-1, -1}));
  vvector<pll> sums_dp(n, vector<pll>(40, {-1, -1}));
  function<pll(int p, int k)> mins =
      (function<pll(int p, int k)>)[&](int p, int k)->pll {
    if (k == 0) {
      return {nexts[p], weights[p]};
    }
    pll &it = mins_dp[p][k];
    if (it.first != -1) return it;
    pll res1 = mins(p, k - 1);
    pll res2 = mins(res1.first, k - 1);
    it.first = res2.first;
    it.second = min(res1.second, res2.second);
    return it;
  };
  function<pll(int p, int k)> sums =
      (function<pll(int p, int k)>)[&](int p, int k)->pll {
    if (k == 0) {
      return {nexts[p], weights[p]};
    }
    pll &it = sums_dp[p][k];
    if (it.first != -1) return it;
    pll res1 = sums(p, k - 1);
    pll res2 = sums(res1.first, k - 1);
    it.first = res2.first;
    it.second = res1.second + res2.second;
    return it;
  };
  function<ll(int p)> culc_mins = (function<ll(int p)>)[&](int p)->ll {
    ll res = INFLL;
    for (int i = (40) * (strlen("") != 0); i < (int)(strlen("") ?: (40)); ++i) {
      if ((1ll << (i)) & k) {
        pll current = mins(p, i);
        chmin(res, current.second);
        p = current.first;
      }
    }
    return res;
  };
  function<ll(int p)> culc_sums = (function<ll(int p)>)[&](int p)->ll {
    ll res = 0;
    for (int i = (39) * (strlen("") != 0); i < (int)(strlen("") ?: (39)); ++i) {
      if ((1ll << (i)) & k) {
        pll current = sums(p, i);
        res += current.second;
        p = current.first;
      }
    }
    return res;
  };
  for (int i = (n) * (strlen("") != 0); i < (int)(strlen("") ?: (n)); ++i) {
    cout << culc_sums(i) << " " << culc_mins(i) << "\n";
  }
}
int main() {
  func();
  return 0;
}
