Help me in solving ADVITIYA5 problem

My issue

I wanted to know why my logic is incorrect here for some big test cases?

My code

for t in range(int(input())):
    n,k=map(int,input().split())
    p=[*range(1,k+2)]
    for i in range(k+2,n+1):
        if i%2==1:
            p.insert(0,i)
        else:
            p.insert(1,i)
    print(*p)
    
            
        
            
    

Problem Link: K Odd Sum Practice Coding Problem - CodeChef

@singleslit
plzz refer my c++ code for better understanding of the logic

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n>>k;
	    for(int i=1;i<k;i++)
	    {
	        cout<<i<<" ";
	    }
	    cout<<k<<" ";
	    for(int i=k+2;i<=n;i+=2)
	    {
	        cout<<i<<" ";
	    }
	    for(int i=k+1;i<=n;i+=2)
	    {
	        cout<<i<<" ";
	    }
	    cout<<endl;
	}
}