.
Ants have 6 legs (Wikipedia, https://en.wikipedia.org/wiki/Ant).
It is amaizing: there are 22000 estimated species, of them 15000 classified,
and ALL have 6 legs (!)
Spiders have 8 legs (Wikipedia, https://en.wikipedia.org/wiki/Spider).
Equations:
A + S = 19, (1) heads, and
6A + 8S = 126 (2) legs.
Multiply (1) by 6 (both sides). You will get
6A + 6S = 114, (1')
6A + 8S = 126.
Now subtract (1') from (2') (both sides). You will get
2S = 126 - 114 = 12 ====> S = = 6.
Answer. 6 spiders and 19-6 = 13 ants.
Check. 13*6 + 6*8 = 126. ! Correct !
Solved.