To combat this problem , NASA scientists spent a decade and $ 12 billion developing a pen that writes in zero gravity , upside down , underwater , on almost any surface including glass and at temperatures ranging from below freezing to over 300 °C .