بِ: preposition.
كَمْ: indeclinable interrogative noun in the genitive position after bi.
رَجُلًا: singular accusative tamyīz.
مَرَرْتَ: past verb with subject tāʾ.
The genitive position of kam and the accusative ending of its tamyīz are fully compatible; do not confuse them.