The Jurassic period was hardly an ideal time to be a tiny, fuzzy creature, what with those massive dinosaurs galumphing around the planet and swarming the skies.

That’s why two newly discovered species, the extinct ancestors of modern mammals, made their homes in treetops and underground burrows, scientists say.

Agilodocodon scansorius and Docofossor brachydactylus (try saying that five times fast), described in two papers published in the journal Science on Friday, are the earliest known examples of arboreal and subterranean mammals. Both were shrew-sized creatures, about three to four inches long, and their fossils were discovered in China.

Neither species is going to win any beauty pageants — artists’ renderings of the animals depict beady-eyed, long-snouted creatures with sharp claws and a mouth full of spiky teeth even a mother couldn’t love. But they did well for themselves in the brutal contest of evolution. Each species exhibits unique adaptations tailored to their specific, secluded habitats, which helped them survive amid giant sauropods and allosaurs.

Agilodocodon, a tree-dweller that lived about 165 million years ago, had curved horny claws to help it climb and spade-like front teeth suited for gnawing into bark. Its limb proportions and flexible joints were similar to those of modern animals that live in trees or bushes, and its teeth resembled those of some gumnivorous (sap-eating) monkeys today.

“It’s amazing that these arboreal adaptions occurred so early in the history of mammals and shows that at least some extinct mammalian relatives exploited evolutionarily significant herbivorous niches, long before true mammals,” said University of Chicago graduate student David Grossnickle, a co-author of the study on Agilodocodon, in a university press release.

The 160-million-year-old Docofossor found its niche by burrowing into the ground. A short, sprawling creature with stumpy legs and wide, shovel-like fingers, it was well suited for digging its way away from trouble. These qualities make it a “dead ringer” for the modern African golden mole (which is basically a fluff ball with a pink nose and stumpy legs), said Zhe-Xi Luo, a University of Chicago professor and author on both papers. The shared traits are so similar that researchers believe the same genes may be responsible, even though the Docofossor and the golden mole come from different branches of the mammalian family tree.

The research teams, which included scientists from the University of Chicago, the Chinese Academy of Geological Sciences and the Beijing Museum of Natural History, said their findings demonstrate early mammals’ ability to diversify to exploit biological niches — a quality modern mammals still exhibit.

“We consistently find with every new fossil that the earliest mammals were just as diverse in both feeding and locomotor adaptations as modern mammals,” Luo said in the University of Chicago press release. “The groundwork for mammalian success today appears to have been laid long ago.”