#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,s,n) for(int i = (s); i < (n); ++i)

typedef long long ll;

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

int H, W;



int main() {
#ifdef CIN_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif

	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		cin >> H >> W;
		if (H == W) {
			cout << "1 0" << endl;
			continue;
		}

		ll C = gcd(H, W);
		ll h = H / C, w = W / C;

		ll siro = (h * w) / 2;
		ll kuro = (h * w + 1) / 2;

		if (!(h & 1) || !(w & 1)){
			// gusu
			cout << "1 1" << endl;
		}
		else{
			cout << kuro << " " << siro << endl;
		}
	}

	return 0;
}