import Control.Monad
import Data.List

solve :: [[Int]] -> [Int]
solve [] = []
solve ([a,b]:qs) =
  e : solve qs
  where
    maxInt = 10^10^10
    e = length  [(x,y) | x<-[1..(max a b)],y<-[1..(max a b)],x/=a&&y/=b&&x*y<a*b]
  

main = do
  q <- read <$> getLine ::IO Int
  ql <- replicateM q $ map read . words <$> getLine ::IO [[Int]]
  mapM print $ solve ql
