let inline scan () = System.Console.ReadLine()
let inline split (s: string) = s.Split(' ')

let q = scan () |> int
for i = 1 to q do
  let [|a_i; b_i|] = scan () |> split |> Array.map int64
  let score_i = a_i * b_i
  printfn "%A" (a_i, b_i)
  
  let mutable count = 0
  let mutable b_start = score_i
  let inline succ () = count <- count + 1

  seq {
    for j = 1L to score_i do
      b_start <- min b_start (score_i / j + 1L)
      if j <> a_i then
        match Seq.unfold (fun x -> if x > 0L then Some (x, x - 1L) else None) b_start |> Seq.tryFind (fun x -> x <> b_i && j * x < score_i) with
          Some x ->
            b_start <- x - 1L;
            succ ();
            yield true
        | None -> yield false
  } |> Seq.takeWhile id |> Seq.tryLast |> ignore;

  printfn "%i" count