main = interact $ unlines . map (show . lagrangeFST . read) . init . lines
 
lagrangeFST n = search 0 n (reverse (takeWhile (<=n) (map (^2) [1..])))
 where
  search _ 0 _ = 1
  search _ _ [] = 0
  search i x dds@(d:ds)
   | i>=4 || x<=0 = 0
   | otherwise = search (i+1) (x-d) (dropWhile (> (x-d)) dds) + search i x ds