#include <bits/stdc++.h>
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
typedef long long ll;
typedef vector<int> vi;
typedef string::const_iterator State;
map<string,bool> mp;
string board[15];
int T;
ll gcd(ll a,ll b)
{
  if(b>a) swap(a,b);
  if(a%b==0) return b;
  else return gcd(b,a%b);
}
int main(int argc,char const* argv[])
{
  int T;
  cin >> T;
  for(int i=0;i<T;i++)
    {
      ll a,b;
      cin >> a >> b;
      if(a==b) cout << 1 << ' ' << 0 << endl;
      else
	{
	  ll GCD=gcd(a,b);
	  if(GCD==1)
	    {
	      if(a%2==0 || b%2==0)
		{
		  cout << 1 << ' ' << 1 << endl;
		}
	      else
		{
		  ll lnum=a*b/2;
		  cout << lnum+1 << ' ' << lnum << endl;
		}
	    }
	  else
	    {
	      a/=GCD;
	      b/=GCD;
	      if(a>=b)
		{
		  swap(a,b);
		}
	      if(a==1)
		{
		  if(b%2==0)
		    {
		      cout << 1 << ' ' << 1 << endl;
		    }
		  else
		    {
		      cout << (b/2)+1 << ' ' << (b/2) << endl;
		    }
		}
	      else
		{
        
		  ll lnum=a*b/2;
		  cout << lnum+1 << ' ' << lnum << endl;
		
		}
	    }
	}
    }
  return 0;
}

