Merging two different models in Keras I am trying to merge two Keras models into a single model and I am unable to accomplish this.

For example in the attached Figure, I would like to fetch the middle layer $A2$ of dimension 8, and use this as input to the layer $B1$ (of dimension 8 again) in Model $B$ and then combine both Model $A$ and Model $B$ as a single model.

I am using the functional module to create Model $A$ and Model $B$ independently.  How can I accomplish this task?

Note: $A1$ is the input layer to model $A$ and $B1$ is the input layer to model $B$.
I figured out the answer to my question and here is the code that builds on the above answer.

from keras.layers import Input, Dense
from keras.models import Model
from keras.utils import plot_model

A1 = Input(shape=(30,),name='A1')
A2 = Dense(8, activation='relu',name='A2')(A1)
A3 = Dense(30, activation='relu',name='A3')(A2)

B2 = Dense(40, activation='relu',name='B2')(A2)
B3 = Dense(30, activation='relu',name='B3')(B2)

merged = Model(inputs=[A1],outputs=[A3,B3])
plot_model(merged,to_file='demo.png',show_shapes=True)


and here is the output structure that I wanted: