#include <iostream>
#include <math.h>
#define MAX_N 10000

using namespace std;

long long A[MAX_N], B[MAX_N], Ar[MAX_N] = { -1 }, Br[MAX_N] = {-1}, R[MAX_N] = { 0 };

int main() {
	int T,i;
	cin >> T;
	for (i = 0; i < T; i++) {
		cin >> A[i] >> B[i];
		long long pom= sqrt(A[i]);
		cout << pom << endl;
		if (B[i] % 2 != 0) R[i] = -1;
		else if (B[i] !=0 && (pom * pom) == A[i]) R[i] = -1;
		else if (B[i] == 0 && (pom * pom) == A[i]) {
			Ar[i] = pom;
			Br[i] = pom;
		}
		else {
			for (long long j = pom; j <= A[i]; j++) {
				if (A[i] % j == 0) if ((j ^ (A[i] / j)) == B[i]) {
					Ar[i] = j;
					Br[i] = A[i] / j;
				}
			}
		}
	}
	for (i = 0; i < T; i++) {
		if (R[i] == -1 || A[i]==-1) cout << -1 << endl;
		else cout << Ar[i] << " " << Br[i] << endl;
	}
}