#include <iostream>
using namespace std;

long long int gcd(long long int a, long long int b)
{
    if (a == 0)
       return b;
    if (b == 0)
    {
        return a;
    }
       
    if (a == b)
        return a;
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int a,b;
        cin>>a>>b;
        if(a==b)
        {
            cout<<0<<" "<<0<<endl;
        }else if (a>b)
        {
            long long int k = a-b;
            long long int n = a%k;
            if(n==0)
            {
                cout<<gcd(a,b)<<" "<<0<<endl;
            }else if(k-n>n)
            {
                cout<<gcd(a-n,b-n)<<" "<<n<<endl;
            }else{
                cout<<gcd(a+k-n,b+k-n)<<" "<<k-n<<endl;
            }
        }else{
            long long int k = b-a;
            long long int n = b%k;
            if(n==0)
            {
                cout<<gcd(a,b)<<" "<<0<<endl;
            }else if(k-n>n)
            {
                cout<<gcd(a-n,b-n)<<" "<<n<<endl;
            }else{
                cout<<gcd(a+k-n,b+k-n)<<" "<<k-n<<endl;
            }
        }
        
    }
}