ANDROUND - AND Rounds

You are given a cyclic array A having N numbers. In an AND round, each element of the array A is replaced by the bitwise AND of itself, the previous element, and the next element in the array. All operations take place simultaneously. Can you calculate A after K such AND rounds?

Input

The first line contains the number of test cases T (T ≤ 50).

There follow 2T lines, 2 per test case. The first line contains two space separated integers N (3 ≤ N ≤ 20000) and K (1 ≤ K ≤ 1000000000). The next line contains N space separated integers Ai (0 ≤ Ai ≤ 1000000000), which are the initial values of the elements in array A.

Output

Output T lines, one per test case. For each test case, output a space separated list of N integers, specifying the contents of array A after K AND rounds.

Example

Input:
2 
3 1 
1 2 3 
5 100 
1 11 111 1111 11111 
 
Output:
0 0 0 
1 1 1 1 1

Added by:Varun Jalan
Date:2010-01-11
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Own Problem, used for Codechef Snackdown http://www.codechef.com/

hide comments
2015-01-08 15:51:08 cegprakash
Go for XORROUND as well!
2014-12-05 18:43:39 T R Sriram
Use scanf and printf or fast I/O, else you will get TLE.
2014-11-29 09:48:09 Ashish Tripathi
b is equal to ( b& INT_MAX).
2014-09-27 18:43:53 sobriquet
My God!! AC in one go.
2014-08-03 19:38:42 maniAC
n = 20000 worked for me.
2014-03-28 17:05:51 Lucas Mageste de Almeida
TLE code even when I just print the input... Something's wrong with the judge
2013-05-15 08:57:23 shalini pandey
can any one suggest me why i am getting TLE in my code??? code id is 9264408..
2013-05-14 06:12:53 昌(尼莫)
The value of N seems to be greater than 20000 .
N = 22000 worked fine for me.

Last edit: 2013-05-14 06:13:12
2013-02-18 09:58:24 ਘੋੜਾ
seems that n > 20000
in test files ...
2013-01-14 19:54:38 Kousik Kumar
Such a great problem!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.