//d = gcd(a,b,x,y) = gcd(b,a % b ,? ,?);
// a * x + b * y = d , b * x1 + (a % b) * y1 = d;
// a * x + b * y = b * x1 + (a % b) * y1 = b * x1 + (a - a / b * b ) * y1 = a * y1 + b * (x1 - a / b * y1)
// x = y1 y = x1 -a / b * y1; x1,y1是下层,x,y是上层,注意代码递归x,y是从下往上的
#include<iostream>
using namespace std;
int gcd(int a,int b,int &x,int &y){
if(b == 0){
x = 1, y = 0;
return a;
}
int d = gcd(b , a % b , x , y);
int t = x;
x = y;
y = t - a / b * y;
return d;
}
int main(){
int n;
scanf("%d",&n);
while(n --){
int a,b,x,y;
scanf("%d%d",&a,&b);
gcd(a,b,x,y);
printf("%d %d\n",x,y);
}
}