When I print or save my tax return as a PDF, I get the federal first, then the state, but then within the state it prints another copy of ALL the federal stuff again. In Adobe it shows you the navigation on the left side, and in that it shows 2016 federal, 2016 state, and under state there is another branch for 2016 federal again.
Some states require that a copy of the Federal return be filed with the state. In that case, you will see a second federal return along with the state.
I am filing Va and MD
How do I know which state is the second copy for?
The Federal return should follow the state return to which it is to be attached.
also please consult the states' Instructions for assembling a state tax return.
as far as I can see, neither MD or VA require you to attach federal tax return, except possibly Schedule C for VA.