#include using namespace std; int S,X,Y; main() { cin>>S; for(;S--;) { cin>>X>>Y; int ans=0; if(X==Y)ans+=X+1; int T=X+Y; for(int i=1;i*i<=T;i++)if(T%i==0) { if(i>2) { long A=i-1; if(A*X>=Y&&(A*X-Y)%(A*A-1)==0&&A*Y>=X&&(A*Y-X)%(A*A-1)==0)ans++; } if(T/i>i&&T/i>2) { long A=T/i-1; if(A*X>=Y&&(A*X-Y)%(A*A-1)==0&&A*Y>=X&&(A*Y-X)%(A*A-1)==0)ans++; } } cout<