Remove the "real" bolts from the stem. Then get some cheap bolts from the hardware store and thread them into the stem's bolt holes, just thread them in there a few turns.
Then hang the stem from a piece of wire that is wrapped around the head of one of the bolts. Paint. Later, when the paint is dry, unthread your junky painted "hardware store bolts" from the stem and mount it on the bike using the unpainted "real" stem bolts.
The cheap bolts will keep the threaded holes of the stem paint-free, and give you a nice place to hang it from during the paint process......................