implicit none
integer(8):: n,i,j,k,count,old_value,value,aaa
integer(8),allocatable,dimension(:):: a,b,c
read (5,*) n
allocate(a(n))
allocate(b(n))
allocate(c(n))

do i=1,n
read(5,*) a(i), b(i)
c(i)=a(i)*b(i)
enddo

!do i=1,n
!write(*,*) a(i),b(i),c(i)
!enddo

do i=1,n
aaa=1
if (a(i)>10) then
    aaa=a(i)-3
endif 

count=aaa-1
old_value=c(i)

do j=aaa,c(i)
    value=min(old_value,(c(i)-1)/j)

    if (old_value==value) then
        value=value-1
    endif


    if (value>0) then
        if (a(i)/=j .and. b(i)/=value) then
            count=count+1
            old_value=value            
        endif

    else
        goto 100
    endif

enddo

100 write(*,*) count

enddo

end
