#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

typedef vector<ll> vii;

vii inv(const vii &A) {
  vii B = A;
  reverse(all(B));
  for (auto &x : B)
    x *= -1;
  return B;
}

vii comb(const vii &A, const vii &B) {
  vii C = A;
  for (int x : B) {
    if (!C.empty() && C.back() == -x) {
      C.pop_back();
    } else {
      C.push_back(x);
    }
  }
  return C;
}

void print(vii A) {
  cerr << A.size() << ": ";
  for (int x : A) {
    cerr << x << " ";
  }
  cerr << "\n";
}

void rem_same(vii &A, vii &B) {
  while (!A.empty() && !B.empty() && A.back() == B.back()) {
    A.pop_back();
    B.pop_back();
  }
}

void diff(vii A, vii B) {
  for (int i = 0; i < 2; ++i) {
    rem_same(A, B);
    reverse(all(A));
    reverse(all(B));
  }
  assert(A.empty());
  //print(A);
  print(B);
  //cerr << endl;
}


typedef vector<int> Perm;

void print(Perm A) {
  for (int x : A) {
    cerr << x + 1 << " ";
  }
  cerr << "\n";
}



int n;

Perm inverse(const Perm &p) {
  Perm q(n);
  for (int i = 0; i < n; ++i) {
    q[p[i]] = i;
  }
  return q;
}

Perm comb(const Perm &p, const Perm &q) {
  Perm s(n);
  for (int i = 0; i < n; ++i)
    s[i] = p[q[i]];
  return s;
}

Perm id() {
  Perm p(n);
  iota(all(p), 0);
  return p;
}

Perm pow(Perm p, ll to) {
  Perm q = id();
  while (to) {
    if (to & 1) {
      q = comb(q, p);
    }
    p = comb(p, p);
    to >>= 1;
  }
  return q;
}

vii my_prod(int n) {
  if (n == 1) {
    return {1};
  } else if (n == 2) {
    return {2};
  }

  vii L = {2}, R = {};
  for (int i = 3; i <= n; ++i) {
    if (i % 6 == 3) {
      L.push_back(-1);
    } else if (i % 6 == 4) {
      R.push_back(-2);
    } else if (i % 6 == 5) {
      L.push_back(-2);
      R.push_back(1);
    } else if (i % 6 == 0) {
      L.push_back(1);
    } else if (i % 6 == 1) {
      R.push_back(2);
    } else if (i % 6 == 2) {
      L.push_back(2);
      R.push_back(-1);
    }
  }

  vii ans = L;
  reverse(all(R));
  for (int x : R)
    ans.push_back(x);

  return ans;
}

Perm get_naive(Perm p, Perm q, int k) {
  if (k == 1) {
    return p;
  } 
  for (int i = 3; i <= k; ++i) {
    p = comb(q, inverse(p));
    swap(p, q);
  }
  return q;
}

Perm get(Perm p, Perm q, ll k) {
  if (k == 1) {
    return p;
  } else if (k == 2) {
    return q;
  }

  Perm x = comb(inverse(p), comb(inverse(q), comb(p, q)));
  Perm y = comb(inverse(p), comb(q, comb(p, inverse(q))));

  Perm L = q;
  Perm R = id();

  ll times = (k - 2) / 6;
  L = comb(L, pow(x, times));
  R = pow(y, times);


  for (int i = 6 * times + 3; i <= k; ++i) {
    if (i % 6 == 3) {
      //L.push_back(-1);
      L = comb(L, inverse(p));
    } else if (i % 6 == 4) {
      //R.push_back(-2);
      R = comb(inverse(q), R);
    } else if (i % 6 == 5) {
      //L.push_back(-2);
      L = comb(L, inverse(q));
      //R.push_back(1);
      R = comb(p, R);
    } else if (i % 6 == 0) {
      //L.push_back(1);
      L = comb(L, p);
    } else if (i % 6 == 1) {
      //R.push_back(2);
      R = comb(q, R);
    } else if (i % 6 == 2) {
      //L.push_back(2);
      L = comb(L, q);
      //R.push_back(-1);
      R = comb(inverse(p), R);
    }
  }

  //print(L);
  //print(R);

  Perm ans = comb(L, R);
  
  return ans;
}

void experiment() {
  vii A = {1};
  vii B = {2};
  for (int i = 3; i < 300; ++i) {
    A = comb(B, inv(A));
    swap(A, B);
    print(B);
    print(my_prod(i));
    assert(B == my_prod(i));
    //cerr << "\n";
    //diff(A, B);
  }
}



  

int main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif

  //experiment();

  ios_base::sync_with_stdio(false);

  cin >> n;
  int k;
  cin >> k;
  Perm p(n), q(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
  }

  for (int i = 0; i < n; ++i) {
    cin >> q[i];
    --q[i];
  }


  //for (int i = 1; i <= 100; ++i) {
    
    //auto A = get(p, q, i);
    //auto B = get_naive(p, q, i);
    //if (A != B) {
      //print(A);
      //print(B);
      //cerr << "i = " << i << "\n";
      //assert(!"coinc");
    //}

    //cerr << i << " ok.\n";
  //}

  Perm ans = get(p, q, k);
  for (int i = 0; i < n; ++i) {
    cout << ans[i] + 1 << " ";
  }
  cerr << "\n";
}



Measured memory_bytes: 4576