#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	ll a,b;
};


ll calc(ll x,ll y){
	if(y == 0){
		return x;
	}else{
		return calc(y,x%y);
	}
}


Info func(ll H,ll W){

	ll num;
	if(H >= W){
		num = calc(H,W);
	}else{
		num = calc(W,H);
	}

	if(num == 1){

		ll S = H*W;

		Info ret;
		if(H%2 == 0 || W%2 == 0){
			ret.a = 1;
			ret.b = 1;
		}else{
			ret.a = (S)/2+1;
			ret.b = (S)/2;
		}
		return ret;
	}else{
		return func(H/num,W/num);
	}
}


int main(){

	int T;
	scanf("%d",&T);

	ll H,W;

	Info ret;

	for(int loop = 0; loop < T; loop++){

		scanf("%lld %lld",&H,&W);
		ret = func(H,W);
		printf("%lld %lld\n",ret.a,ret.b);
	}

	return 0;
}

