import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

long lcm(long a, long b) {
    long g = gcd(a, b);
    return a / g * b;
}

void main() {
    int T; readf("%d\n", &T);
    foreach (t; 0 .. T) {
        stdout.flush;
        int H, W; readf("%d %d\n", &H, &W);
        if (H == W) {
            writeln("1 0");
            continue;
        }
        if (H > W) swap(H, W);
        if (H % 2 == 0 || W % 2 == 0) {
            writeln("1 1");
        } else {
            long g = gcd(H, W);
            H /= g; W /= g;
            long L = lcm(H, W);
            long w = (L + 1) / 2;
            long r = L / 2;
            writefln("%s %s", w, r);
        }
    }
}