Mastering the art of deduction was once thought to be a singularly human skill, but research has since shown that animals, including chimpanzees, birds, rats, fish and geese, are capable of using a form of logic called transitive inference. Defined as the ability to infer unknown relationships on the basis of known ones—for example, if Ryan is taller than Scott and Scott is taller than Mike, one can surmise that Ryan is taller than Mike—transitive inference has previously been observed solely in vertebrates.

Now, a new study published in Biology Letters adds a surprising invertebrate to this pool of logic-equipped animals: paper wasps, a nearly ubiquitous subfamily of stinging insects found on every continent except Antarctica. According to CNN’s Jack Guy, the creatures, which derive their name from paper-like nests made out of chewed wood mixed with saliva, earned the distinction of being the first invertebrates capable of logic by passing a test similar to one failed by honeybees in 2004.

Scientists led by Elizabeth Tibbetts, an evolutionary biologist at the University of Michigan, gauged paper wasps’ deductive reasoning skills by training members of two subspecies, Polistes dominula and Polistes metricus, to differentiate between five colors labeled A through E, as Becky Ferreira reports for Vice.

During each trial run, Tibbetts and her team placed a wasp in the center of a rectangular arena split between two of the colors. One side was a “safety zone,” and the other delivered a “slightly unpleasant” shock of 0.4 volts. When A was paired with B, the former was safe, and the latter was electrified. When B was paired with C, the B side was safe and the C side was electrified. This pattern continued through the D and E pairing, leaving the wasps to deduce that A was always safe, E was always electrified, and B, C and D were sometimes safe, sometimes electrified. To ensure the wasps fully grasped this safety hierarchy, the researchers began one group’s training with the A and B pairing and the other’s with the D and E pairing.

After learning these patterns, the wasps received a new challenge: deciding between previously unseen pairings such as A and E or B and D. According to New Scientist’s Chelsea Whyte, 65 percent of the insects correctly chose B over D, exhibiting a level of accuracy better than chance. The wasps chose A over E at roughly the same rate, but as Tibbetts tell Whyte, this result may be less significant because A was always shock-free, and E always delivered a shock.

Still, Tibbetts explains to The New York Times’ Cara Giaimo, the findings suggest the wasps “are organizing all those pairs into a linear hierarchy in their head”—an impressive feat given the fact that the size of their nervous systems and brains is on par with that of honeybees, an invertebrate species unable to accomplish similar logic-based tasks.

The crux of the matter may be paper wasps’ complex social behaviors. As CNN’s Guy writes, the insects’ colonies host multiple reproductive females, or foundresses, that compete for dominance during the spring.

“Some wasps will be fighting; some wasps will be watching the fights,” Tibbetts tells Giaimo. “It’s a very exciting time.”

Comparatively, Gavin Broad, principal curator in charge of insects at London’s Natural History Museum, says to Guy, honeybees and other wasp species are less “flexible” than paper wasps when it comes to shifting from worker to queen.

Broad continues, “Dominance hierarchies are important to these paper wasps as the workers can become the queens, whereas a worker honey bee can never become a queen."

Tibbetts has previously shown that paper wasps can identify and remember one another based on their distinct facial patterns. This ability raises the question of whether a wasp that beat a fellow foundress could infer that she is also likely to defeat wasps bested by her original sparring partner. (If Sarah wins a brawl with Rachel and then witnesses a fight where Rachel beats Donna, for instance, will Sarah be able to surmise that she could probably beat Donna, too?)

The Biology Letters study doesn’t offer a decisive answer to this query, but it does lay out the groundwork for the deductive reasoning skills needed to make such determinations. Moving forward, the team hopes to gain a better understanding of how—or if—wasps use transitive inference in social situations.

“We’re not saying that wasps used logical deduction to solve this problem, but they seem to use known relationships to make inferences about unknown relationships,” Tibbetts concludes in a press release. “Our findings suggest that the capacity for complex behavior may be shaped by the social environment in which behaviors are beneficial, rather than being strictly limited by brain size.”