CI stages vs dependencies

I am having trouble with stages vs dependencies in gitlab-ci.yml files.

I habe setup stages like this:

stages:
    - test
    - build
    - deploy

but then have two independet build jobs and two independet deploy jobs. With dependencies I get this

a

What I am really after though is this

b

Any idea on how to do that without createing two separate stages for the deploy task?