#include<stdio.h>
char isprime[2000010];
int sq[2000010];
long long exgcd(long long a,long long b,long long *x,long long *y)
{
if(!b)
{
(*x)=1;
(*y)=0;
return a;
}
long long r=exgcd(b,a%b,&(*x),&(*y)),t=(*x);
(*x)=(*y);
(*y)=t-a/b*(*y);
return r;
}
long long gcd(long long a,long long b)
{
return (b==0)?a:gcd(b,a%b);
}
char cal(long long a,long long b,long long c,long long *x,long long *y)
{
if(c%gcd(a,b)!=0)
{
return 0;
}
long long q=exgcd(a,b,&(*x),&(*y));
long long v=c/q;
(*x)*=v;
(*y)*=v;
(*y)*=-1;
return 1;
}
int main()
{
isprime[0]=isprime[1]=1;
int i;
sq[1]=1;
for(i=2;i<=20000;i++)
{
if(!isprime[i])
{
int j;
for(j=i*i;j<=2000000;j+=i)
{
isprime[j]=1;
}
}
if(i*i<=2000005)
{
sq[i*i]=i;
}
}
for(i=1;i<2000005;i++)
{
if(!sq[i])
{
sq[i]=sq[i-1];
}
}
int T;
scanf("%d",&T);
while(T--)
{
long long a,b;
scanf("%lld%lld",&a,&b);
if(b==1)
{
printf("-1 -1 -1 -1\n");
}
else if(a%b==0)
{
int x=a/b;
printf("%d 1 %d 1\n",x+1,1);
}
else if(!isprime[b])
{
printf("-1 -1 -1 -1\n");
}
else
{
int flag=1;
long long l,r;
for(l=2,r=sq[b]+2;l<=r+1;l++,r--)
{
if(l>=2&&l<b&&b%l==0)
{
long long x=l,y=b/x,c,e;
if(cal(y,x,a,&c,&e))
{
if(c<=0||e<=0)
{
if(c<=0&&e<=0)
{
printf("%lld %lld %lld %lld\n",-e+y,y,-c+x,x);
}
else if(e<=0)
{
long long q=(-e)/y+2;
printf("%lld %lld %lld %lld\n",c+x*q,x,e+y*q,y);
}
}
else
{
printf("%lld %lld %lld %lld\n",c,x,e,y);
}
flag=0;
break;
}
}
if(r>=2&&r<b&&b%r==0)
{
long long x=r,y=b/x,c,e;
if(cal(y,x,a,&c,&e))
{
if(c<=0||e<=0)
{
if(c<=0&&e<=0)
{
printf("%lld %lld %lld %lld\n",-e+y,y,-c+x,x);
}
else if(e<=0)
{
long long q=(-e)/y+2;
printf("%lld %lld %lld %lld\n",c+x*q,x,e+y*q,y);
}
}
else
{
printf("%lld %lld %lld %lld\n",c,x,e,y);
}
flag=0;
break;
}
}
}
if(flag)
{
printf("-1 -1 -1 -1\n");
}
}
}
return 0;
}