//W4P3R
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register ll
#define fr first
#define sd second
#define pa pair<int,int>
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define lowbit(x) (x&(-x))
#define Z(x) (x>=mod?x-mod:x)
#define N 210
#define M 100010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int t,S,T;
int n,k;
struct edge
{
	int next,to,fl,v;
}e[M<<1];
int head[N],cnt=1;
pa p[N];int a[N],b[N];
int minn[N],dist[N],pre[N];
int vis[N];queue<int>Q;
inline void add(int x,int y,int fl,int v)
{
	e[++cnt]=(edge){head[x],y,fl,v};head[x]=cnt;
	e[++cnt]=(edge){head[y],x,0,-v};head[y]=cnt;
}
void Update(int x,int fl)
{
	e[pre[x]].fl-=fl;
	e[pre[x]^1].fl+=fl;
	if(e[pre[x]^1].to)Update(e[pre[x]^1].to,fl);
}
inline void spfa()
{
	FOR(i,1,T)dist[i]=-inf;Q.push(S);vis[S]=1;dist[S]=0;minn[S]=inf;
	while(!Q.empty())
	{
		int x=Q.front();Q.pop();vis[x]=0;
		for(re i=head[x];i;i=e[i].next)
		{
			if(e[i].fl&&dist[e[i].to]<dist[x]+e[i].v)
			{
				dist[e[i].to]=dist[x]+e[i].v;minn[e[i].to]=min(e[i].fl,minn[x]);
				pre[e[i].to]=i;
				if(!vis[e[i].to]){Q.push(e[i].to);vis[e[i].to]=1;}
			}
		}
	}
	if(dist[T]==-inf)return ;
	Update(T,minn[T]);
}
inline int EK()
{
	int sum=0;
	while(true)
	{
		spfa();
		if(dist[T]==-inf)return sum;
		sum+=minn[T]*dist[T];
	}
}
int main()
{
	//ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	t=read();
	while(t--)
	{
		n=read(),k=read();k=min(k,n);T=n+k+2;
		cnt=1;memset(head,0,sizeof(head));
		FOR(i,1,n)a[i]=read(),b[i]=read();
		if(n<=k)
		{
			FOR(i,1,n)p[i]=mp(b[i],i);
			sort(p+1,p+n+1);
			FOR(i,1,n)printf("%d ",p[i].sd);puts("");continue;
		}
		FOR(i,1,n)add(S,i,1,0);
		FOR(i,1,k)add(i+n,T,1,0);
		add(n+k+1,T,n-k,0);
		FOR(i,1,n)FOR(j,1,k)
		{
			add(i,n+j,1,a[i]+b[i]*(j-1));
		}
		FOR(i,1,n)add(i,n+k+1,1,b[i]*(k-1));
		EK();
		vector<int>ans;
		FOR(x,n+1,n+k-1)for(re i=head[x];i;i=e[i].next)
		{
			if(e[i].fl&&e[i].to<=n&&e[i].to)ans.pb(e[i].to);
		}
		int p=n+k+1;
		for(re i=head[p];i;i=e[i].next)
		{
			if(e[i].fl&&e[i].to<=n&&e[i].to){ans.pb(e[i].to);ans.pb(-e[i].to);}
		}
		p=n+k;
		for(re i=head[p];i;i=e[i].next)
		{
			if(e[i].fl&&e[i].to<=n)ans.pb(e[i].to);
		}
		printf("%d\n",(int)ans.size());
		for(int v:ans)printf("%d ",v);puts("");ans.clear();
	}
	return 0;
}
//check first submit second
