Kesuvos10: 1
מִי שֶׁהָיָה נָשׂוּי שְׁתֵּי נָשִׁים, וּמֵת — הָרִאשׁוֹנָה קוֹדֶמֶת לַשְּׁנִיָּה, וְיוֹרְשֵׁי הָרִאשׁוֹנָה קוֹדְמִים לְיוֹרְשֵׁי שְׁנִיָּה.  נָשָׂא אֶת הָרִאשׁוֹנָה, וּמֵתָה; נָשָׂא שְׁנִיָּה, וּמֵת הוּא — שְׁנִיָּה וְיוֹרְשֶׁיהָ קוֹדְמִים לְיוֹרְשֵׁי הָרִאשׁוֹנָה.
[If] one was married to two wives, and he died, the first one takes precedence over the second one, and the first one’s heirs take precedence over the second one’s heirs.  [If] he married the first one, and she died; and he married a second one, and he died, the second one and her heirs take precedence over the first one’s heirs.