Problem: It is the hard version of the problem. The only difference is that in this version 3 ≤ k ≤ n.

You are given a positive integer n. Find k positive integers a_1, a_2, …, a_k, such that:

  * a_1 + a_2 + … + a_k = n 
  * LCM(a_1, a_2, …, a_k) ≤ n/2 



Here LCM is the [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) of numbers a_1, a_2, …, a_k.

We can show that for given constraints the answer always exists.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.

The only line of each test case contains two integers n, k (3 ≤ n ≤ 10^9, 3 ≤ k ≤ n).

It is guaranteed that the sum of k over all test cases does not exceed 10^5.

Output

For each test case print k positive integers a_1, a_2, …, a_k, for which all conditions are satisfied.

Example

Input


2
6 4
9 5


Output


1 2 2 1 
1 3 3 1 1 

Solution (in JAVA):

Solution:
import java.util.Scanner;
import java.util.ArrayList;
public class k_LCM_hard {
    public static void main(String[] args) {
        Scanner inscan = new Scanner(System.in);
        int testCount = inscan.nextInt();
        ArrayList<Long> outputs= new ArrayList<Long>(3*testCount);
        for(int i=0;i<testCount;i++){
            long currentNum = inscan.nextLong();
            long buckets= inscan.nextLong();
            for(int j=0;buckets>3;){
                outputs.add((long)1);
                buckets--;
                currentNum--;
            }
            if(currentNum%2==1){
                outputs.add((currentNum)>>1);
                outputs.add((long)(currentNum)>>1);
                outputs.add((long)1);
            }
            else if(currentNum%4==0){
                outputs.add((currentNum)>>1);
                outputs.add((currentNum)>>2);
                outputs.add(currentNum>>2);
            }
            else{
                outputs.add((currentNum-2)>>1);
                outputs.add((long)(currentNum-2)>>1);
                outputs.add((long)2);
            }
            outputs.add((long)0);

            
        }
        for(long val:outputs)
            {
                if(val==0)
                    System.out.println();
                else
                    System.out.print(val+" ");
            }
    }
    public static void fillArr(ArrayList<Long> arr, long val,long count){
        for(count=count;count>0;count--)
        {
            arr.add(val);
        }
    }
}
/*
3 3
4 3
5 5
6 3
7 4
8 5
9 5
10 7
11 3
12 4
13 9
14 7
15 8
16 10
17 3
18 6
19 6
20 8
21 10
22 3
23 3
24 5
25 8
26 5
27 9
28 4
29 6
30 10
31 6
32 10
33 6
34 9
35 3
36 3
37 9
38 8
39 5
40 6
41 9
42 6
43 7
44 4
45 8
46 10
47 6
48 5
49 7
50 10
51 4
52 3
53 9
54 5
55 5
56 4
57 5
58 10
59 5
60 4
61 7
62 6
63 7
64 9
65 7
66 10
67 7
68 5
69 8
70 3
71 10
72 8
73 3
74 9
75 9
76 4
77 10
78 8
79 10
80 7
81 5
82 10
83 6
84 4
85 8*/