#include long long getCnt(long long a,long long x,long long y){ //printf("a = %lld\n",a); if(a==1){ if(x!=y) return 0; else return x-1; } else{ //b-c long long k = (x-y)/(a-1); //b-c+ab+c = (a+1)b long long kk = k+x; if(kk%(a+1)) return 0; else{ long long b = kk/(a+1); long long c = b-k; if(b>0 && c>0) return 1; else return 0; } } } int main(){ int T; scanf("%d",&T); while(T--){ long long x,y; scanf("%lld%lld",&x,&y); long long absDiff = x>y?x-y:y-x; long long ans = 0; //for a-1 //a-1 == 0 for(long long i = 1; i*i <= absDiff; i++){ //printf("i = %lld\n",i); if(absDiff%i==0){ ans += getCnt(i+1,x,y); if(absDiff/i!=i) ans += getCnt((absDiff/i)+1,x,y); } } printf("%lld\n",ans); } return 0; }