import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } final long MOD=(long)1e9+7; ArrayList gen_divs(long n) { ArrayList divs=new ArrayList<>(); if (n%2==0) { for (long div=2;div*div<=n;++div) { if (n%div!=0) continue; divs.add(div); divs.add(n/div); } } else { for (long div=3;div*div<=n;div+=2) { if (n%div!=0) continue; divs.add(div); divs.add(n/div); } } if (divs.size()>2 && divs.get(divs.size()-1)==divs.get(divs.size()-2)) { divs.remove(divs.size()-1); } return divs; } void run() { Scanner sc = new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int S=sc.nextInt(); while (S-->0) { long ans=0; long x=Long.parseLong(sc.next()); long y=Long.parseLong(sc.next()); if (x divs=gen_divs(x+y); for (long d:divs) { if (d==2) continue; long a=d-1; long bc=(x+y)/d; long b=(x-bc)/(a-1); long c=bc-b; if (x!=a*b+c || y!=a*c+b || a<=0 || b<=0 || c<=0) continue; ans+=1; } pw.println(ans); } pw.flush(); } void tr(Object...o) {System.out.println(Arrays.deepToString(o));} }