
#include <string>
#include <vector>
#include <array>
#include <memory>
#include <iostream>
#include <algorithm>

using namespace std;
int main(void) {
	//boost::shared_ptr<vector<string>>  log(boost::make_shared<vector<string>>());
	//log->push_back("dd");
	//log->push_back("dde");
	//boost::shared_ptr<vector<string>>  blog(boost::make_shared<vector<string>>());
	//blog->push_back("fsdfsdfd");
	//OpChara a(3,log);
	//OpChara b(2,log);
	//OpChara c(1, log);
	//log->push_back("dde3");
	//std::ofstream ofs("output1.txt");
	//assert(ofs);
	//boost::archive::text_oarchive oa(ofs);
	//oa << (a);
	//ofs.close();
	//std::ofstream cofs("output2.txt");
	//assert(cofs);
	//boost::archive::text_oarchive coa(cofs);
	//coa << (b);
	//cofs.close();

	//// de-serialize
	//std::ifstream ifs("output1.txt");
	//assert(ifs);
	//boost::archive::text_iarchive ia(ifs);

	//ia >> (b);
	//
	//ifs.close();
	//std::ifstream cifs("output2.txt");
	//assert(cifs);
	//boost::archive::text_iarchive iac(cifs);
	//iac >> c;
	//
	//// check
	//b.actionlog->push_back("111");

	/*int n, m;
	cin >> n >> m;
	vector<vector<tyu>> Pots;
	for (int i = 0; i < n; ++i) {
		Pots.push_back(vector<tyu>());
		int k;
		cin >> k;
		for (int j = 0; j < k; ++j) {
			int s,h;
			cin >> s >> h;
			Pots[i].push_back({ s,h });
		}
	}
	double ans=0;
	while (1) {

	
		vector<memo> amemo;
		for (int i = 0; i < n; ++i) {
			double h = 0;
			int taiseki = 0;
			for (int j = 0; j < Pots[i].size(); ++j) {
				bool flag = false;
				if (m > taiseki+ Pots[i][j].height*Pots[i][j].wide) {
					h += Pots[i][j].height;
					taiseki += Pots[i][j].height*Pots[i][j].wide;
				}
				else {
					flag = true;
					h += (double(m - taiseki)) / Pots[i][j].wide;
					taiseki = m;
				}
				const double akouritu = double(taiseki) / h;
				amemo.push_back({ akouritu, i, h,j,taiseki });
				if (flag) { break; }
			}
		}
		sort(amemo.begin(), amemo.end(), [](const memo m1, const memo m2) {return m1.kouritu < m2.kouritu; });
		bool flag=false;
		memo me = *amemo.begin();
		m -= me.taiseki;
		if (m < 0.0000000001) {
			flag = true;
		}
		ans += me.height;
		for (int i = 0; i < me.num + 1;++i) {
			Pots[me.id].erase(Pots[me.id].begin());
		}
		if (flag) {
			break;
		}
		
	}
	printf("%.10d", &ans);
	cout << ans;*/
	int t;
	cin >> t;
	for (int k = 0; k < t; ++k) {
		long long int h, w;
		cin >> h >> w;
		if (h == w) {
			cout << 1 << " " << 0 << endl;
			continue;
		}
		long long int l = 1;
		long long int a = h;
		long long int b = w;
		while (1) {
			if (a > b) {
				a = a%b;
				if (a == 0) {
					l = b;
					break;
				}
			}
			else {
				if (a == b) {
					l = a; break;
				}
				long long int ddd = a;
				a = b;
				b = ddd;
			}
		}
		h /= l;
		w /= l;
		
		if (h % 2 == 1 && w % 2 == 1) {
			cout << (h*w + 1) / 2 << " " << (h*w - 1) / 2 << endl;
		}
		else {
			cout << 1 << " " << 1 << endl;
		}
		
	}
	
	return 0;

}