#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
int gcd(int a,int b){
	while(a){
		b%=a;swap(a,b);
	}
	return b;
}
int main(){
	int T;scanf("%d",&T);
	while(T--){
		int a,b;scanf("%d%d",&a,&b);
		int g=gcd(a,b);
		int A=a/g;
		int B=b/g;
		if(A%2&&B%2){
			printf("%lld %lld\n",(long long)A*B/2+1,(long long)A*B/2);
		}else{
			printf("1 1\n");
		}
	}
}