#include using namespace std; #include using namespace atcoder; using mint=modint998244353; //1000000007; using ll=long long; using pp=pair; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(int i=0;i<(int)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) int main(){ int t;cin>>t; rep(tt,t){ int x,y;cin>>x>>y; int z=x+y; int ans=0; if(x==y)ans=x; for(int i=3;i*i<=z;i++)if(z%i==0){ int j=z/i; if(j<3)continue; int a=i-1; int b=(x-j)/(a-1); int c=j-b; if(b>0&&c>0&&x==b*a+c&&y==a*c+b)ans++; a=j-1; b=(x-i)/(a-1); c=i-b; if(b>0&&c>0&&x==b*a+c&&y==a*c+b)ans++; } cout<