#include<bits/stdc++.h>
using namespace std;

char infile[100], outfile[100];

long long int A[100100];

int main(){
    long long int n, m, a, b, s = 0, i, I, T;
    scanf("%lld",&T);
	srand(time(NULL));
	for(I=1;I<=T;I++){
        sprintf(infile, ".%d.in", I);
        freopen(infile, "w", stdout);
        scanf("%lld %lld", &n, &m);
        printf("%lld %lld\n",n,m);
        s = 0;
        for(i=0;i<=n;i++)A[i]=0;
        for(i=0;i<m;i++){
            a = ((((rand()%n)*rand())%n)*rand())%n+1;
            b = ((((rand()%100)*rand())%10000)*rand())%10000+1;

            printf("%lld %lld\n", a, b);
            A[a] = A[a] + b;
            s = s+b;
        }
        sprintf(outfile, ".%d.out", I);
        freopen(outfile, "w", stdout);

        for(i=1;i<=n;i++){
            printf("%lld ", s - A[i]);
        }
	}
}
