Where you were living when you received each type of income is important to the answer but you didn't tell us that so I'll provide the general rules.
The state you are living in gets to tax all of your world-wide income - it doesn't matter where it comes from.
A state gets to tax income earned within its borders: rental property there; you were physically in the state earning income; etc.
So, it's just a matter of income allocation for both part-year MD & VA returns, and the nonresident NC return if you were there when you earned that contract income.
MD and VA have reciprocity such that they don't tax the wages of each other's residents. So, for instance, don't include in MD income wages earned there while you lived in VA. And vice versa.