Merging two masked images

Use a Lerp node (Linear Interpolation) for this.
Where the Alpha is one, B is used - where it is zero, A is used. Everything in between is interpolated. (Alpha = 0.5 means 50% A + 50% B)

You can also use a single texture and store the two masks in different channels, then multiply single channels with the desired colours.