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;
}

void main() {
    int T; readf("%d\n", &T);
    foreach (t; 0 .. T) {
        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 {
            int g = gcd(H, W);
            H /= g; W /= g;
            int m = W / (2 * H) * H;
            int w = m * H, r = m * H;
            W %= 2 * H;
            w += min(W, H);
            W -= min(W, H);
            r += W;
            writefln("%d %d", w, r);
        }
    }
}