#include <bits/stdc++.h>
using namespace std;
#define int long long
main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(15) << fixed;
    int t;
    cin >> t;
    while(t--){
        int n, k;
        cin >> n >> k;
        vector < vector <int> > a;//(n, vector <int> (3) );
        for(int i = 0; i < n; ++i){
            int c, d;
            cin >> c >> d;
            a.push_back({d,c,i+1});
        }
        sort(a.begin(), a.end());
        int inf = -1e18; 
        vector <vector <int> > dp(n+1, vector <int> (n+1, -inf));
        dp[0][0] = 0;
        for(int i = 1; i <= n; ++i){
            dp[i][0] = dp[i-1][0] + k*a[i-1][0];
            for(int j = 1; j <= min(k, i); ++j){
                dp[i][j] = max(dp[i-1][j] + (k-1)*a[i-1][0], dp[i-1][j-1] + a[i-1][1] + (j-1)*a[i-1][0]);
            }
        }
        vector <int> b(n);
        {
            int r = n, e = k;
            while(e > 0 && r > 0){//r > 0
                if (e == r){
                    for(int i = r-1; i >= 0; --i){
                        b[i] = 1;
                    }
                    break;
                }
                if(dp[r-1][e] + (k-1)*a[r-1][0] <= dp[r-1][e-1] + a[r-1][1] + (e-1)*a[r-1][0]){
                    b[r-1] = 1;
                    --e;
                }
                --r;
            }
        }
        cout << 2*n - k << '\n';
        int r = 0;
        for(int i = 0; i < n; ++i){
            if(r == k-1)break;
            if(b[i]) {
                cout << a[i][2] << ' ';
                ++r;
                if(r == k-1)break;
            }
        }
        for(int i = 0; i < n; ++i){
            if(!b[i]) {
                cout << a[i][2] << ' ';
                cout << -a[i][2] << ' ';
            }
        }
        for(int i = n-1; i >= 0; --i){
            if(b[i]) {
                cout << a[i][2] << '\n';
                break;
            }
        }
    }
}
