Multiple State Filing - State Income Allocation (MA, MD, DC)

I lived in MA for 1/1/21 - 7/9/21 and physically moved to MD for 7/10/21 - 12/31/21.

 

For the entire time, I worked for an MA-based company. Due to company-specific tax policies, my company allowed me to work at a DC office and withheld my taxes in DC for 9/27/21 - 12/31/21 (prior to when state taxes were withheld in MA, despite updating my personal address with the company via Workday).

 

As such, I received two W-2s, where the first one includes all of my annual income (for boxes 1 - 12) and shows DC wages and taxes for boxes 15-17 relating to my wage for 9/27/21 - 12/31/21. The second W-2 just includes my MA state taxes for box 15-17 (with boxes 1 - 12 empty) in connection with my wage for 1/1/21 - 9/26/21.

 

I am really confused as to how to populate non-Maryland income, Massachusetts Income While Resident, and Massachusetts Income While Nonresident.

 

Would it be correct to populate these fields based on my W-2? - As in my MA state wage and income tax from my second W-2 gets used for Non-Maryland income AND my Massachusetts Income While Resident, with my DC state wage and income tax from my first W-2 gets used for Massachusetts Income While Nonresident.

 

OR should I rather calculate the allocation based on my physical time in these states? If the latter, how would I ensure that the calculations are not resulting in duplicate taxes?