#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=1;i<n;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) REP(i,v.size())cout<<#v<<"["<<i<<"]: "<<v[i]<<endl
#define ALL(a) (a).begin(),(a).end()

ll gcd(ll a,ll b){
  ll c;
  while(a!=0){
    c=a;
    a=b%a;
    b=c;
  }
  return b;
}

int main(){
  ll T;
  cin>>T;
  REP(_t,T){
    ll h,w;
    cin>>h>>w;
    if(h==w){
      cout << "1 0" << endl;
      continue;
    }
    if(h%2==0 || w%2==0){
      cout << "1 1" << endl;
      continue;
    }
    ll g = gcd(h,w);
    h /= g;
    w /= g;
    ll tot = h*w;
    ll first = tot/2;
    first += 1;
    ll second = tot-first;
    cout << first << " " << second << endl;
  }
  return 0;
}