The question transfers to the problem in the anology of tree and seed as to which came first.
Avirodha Adhyaya of Brahma Sutra , has the answer to your question.
(Courtesy: English Translation by Swami Sivananda)
Vaishamyanairghrinye na sapekshatvat tatha hi darsayati 2.1.34
Vaishamya: inequality, partiality; Nairghrinye: cruelty, unkindness; Na: not (cannot be ascribed to Brahman); Sapekshatvat: because of dependence upon, as it is dependent on something else, i.e., upon the Karma of the souls; Tatha: so; Hi: because; Darsayati: the scripture declares
Partiality and cruelty cannot (be ascribed to Brahman) on account of His taking into consideration (other reasons in that matter viz., merit and demerit of the souls), for so (scripture) declares.
Na karmavibhagaditi chet na anaditvat 2.1.35
Na: not; Karmavibhagat: because of the non-distinction of work (before creation); Iti chet: if it be said, if it be objected in this way; Na: no, the objection cannot stand; Anaditvat: because of beginninglessness.
If it be objected that it (viz., the Lord's having regard to merit and demerit) is not possible on account of the non-distinction (of merit and demerit before creation), (we say) no, because of (the world) being without a beginning.
An objection against Sutra 34 is raised and refuted.
The Sutra consists of two parts, viz., an objection and its reply. The objective portion is 'Na karmavibhagaditi chet' and the reply portion is 'Na anaditvat'.
An objection is raised now. The Sruti says, "Being only this was in the beginning, one without a second." There was no distinction of works before creation of the world. There was only the absolutely One Real Being or Brahman. The creation at the beginning of one man as rich and of another as poor and unhappy cannot certainly depend on the respective previous good or bad deeds. The first creation must have been free from inequalities.
This objection cannot stand. The creation of the world is also without a beginning. There was never a time that may be said to be an absolute beginning. The question of first creation cannot arise. Creation and destruction of the world following each other continually by rotation is without any beginning and end. The condition of individual souls in any particular cycle of creation is predetermined by their actions in the previous cycle.