main=getContents>>=(mapM putStrLn . map (g . map read) . map words . init . lines)
g = snd . maximum . flip zip ["a","b"] . map f
f n = let pfs = [ p | p <- takeWhile (<=n) ps, mod n p == 0]
      in maximum pfs * 2 - sum pfs
primes (x:xs) = x:primes[ y | y <- xs, not (mod y x == 0)]
ps = primes [2..]