ans' 0 _ = []
ans' n i =
  let j = i*i
      i'= (j `mod` 1000000) `div` 100
  in
    i':(ans' (n-1) i')

ans i =
  ans' 10 i

cs i = "Case " ++ show(i) ++ ":"

pr :: Int -> [[Int]] -> IO ()
pr _ [] =
  return ()
pr i (o:os) =  do
  let hd = cs i
  putStrLn hd
  mapM_ print o
  pr (i+1) os

main = do
  _ <- getLine
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = map ans i
  pr 1 o