#include<bits/stdc++.h>
using namespace std;
long long int delilac(long long int x)
{
	long long int n=3;
	for(n;n<x;n+2)
	{
		if(x%n==0)
			return n;
	}
	return -1;
	
}
int main()
{
	long long int p,a[10000],b[10000],n,x[10000],y[10000];
	cin>>n;
	int i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		cin>>b[i];
		if(b[i]==0)
		{
			p=sqrt(a[i]);
			x[i]=p;
			y[i]=p;
		}
		if(b[i] != 0)
		{
			x[i]=delilac(a[i]);
			y[i]=a[i]/x[i];
		}
		
	}
	for(i=0;i<n;i++)
	{
		if(x[i]*y[i] != a[i] || x[i]<0)
			{
				cout<<-1;
				printf("\n");
				}
		if(b[i] != 0 && x[i] == y[i])
		{	
			cout<<-1;
			printf("\n");
				}		
		else
		{
			cout<<x[i];
			printf(" ");
			cout<<y[i];
			printf("\n");
					}			
	}
	
}