Count all your outs after the flop.

so in your example: You have QJs: Flop is As Th 3s
if someone has an Ace you are behind, so your outs are 4 (for the K) + 9 (flush) - 1 (Ks) = 12