HARRISBURG, Pa. (AP) — Partisan control of the Pennsylvania House of Representatives remained up in the air Thursday, two days after 100 Democrats and 100 Republicans were elected, leaving three races in swing districts still unresolved.

All three of the seats are held by Republicans in the General Assembly session that ends later this month. It may be weeks before county elections officials finish vote counting to determine winners.

Democratic leaders expressed confidence Wednesday they had wrested back majority control of the House for the first time in 12 years. But two of their successful reelection candidates also won races this week for Congress and lieutenant governor, while a third died in early October.

Lawmakers are scheduled to return to Harrisburg early next week so the caucuses can separately pick their own leaders. The projected majority will designate someone to stand for the chamber-wide contest for speaker on Jan. 3.

If Republicans control the chamber, that will likely be incumbent Speaker Bryan Cutler, R-Lancaster. But on Wednesday, House Minority Leader Joanna McClinton, D-Philadelphia, predicted her party would retake the majority, which would make her the state’s first female speaker.

Republicans had a 113-90 majority going into the election. Democratic strength in the races for governor and U.S. Senate, along with more favorable district maps, helped them claw back into contention.

In Bucks County, state Rep. Todd Polinchock would need a major boost from provisional and overseas ballots to net him the hundreds of votes he’d need to get a third term. Thursday afternoon, he posted on Facebook: “Thank you to my supporters who gave me the opportunity of a lifetime to serve my community. God bless.”

Another Bucks County race, in a district held most recently by Republican Rep. Frank Farry, has the two candidates neck and neck. And in Montgomery County, longtime Democratic target Rep. Todd Stephens, a six-term Republican, is also in a very close race.

Democrats say they expect Allegheny County Reps. Summer Lee and Austin Davis to return briefly in January to help pick the 2023-24 speaker despite them winning higher office this week. Still, the Oct. 9 death of Rep. Tony DeLuca makes a 101-101 deadlock possible.

The speaker will have to schedule special elections for the Lee, Davis and DeLuca vacancies. If the Democrats hold the speakership, those elections are likely to occur in March. If Republicans make the decision, filling those seats in the May 16 spring primary is much more likely.

The scenario has legal and procedural experts bracing for what could be a protracted stalemate over control in early January, and puzzling over the implications if McClinton were to get elected speaker on the strength of votes from two members who then immediately resigned.

“I wanted to go out quietly,” said House Parliamentarian Clancy Myer, who plans to retire at the end of January after more than four decades working in the Legislature. “But this isn’t working out well.”

When the House assembles Jan. 3, Chief Clerk Brooke Wheeler will preside until a candidate for speaker gets a majority vote.

A one-seat Democratic margin after Election Day results, followed by the death of a reelected Democrat, occurred in the state House in 1978, when Bethlehem state Rep. Frank Meluskey died of heart disease weeks after the vote. The chamber appeared deadlocked at 101-101 until a recount in a Somerset County race flipped the chamber to a GOP majority, 102-100.

In 1994, Democratic state Rep. Tom Stish, of Luzerne County, switched parties a week after being elected, turning over control to Republicans by a single seat.

More recently, Democrats with a 102-101 majority at the start of session in 2007 banded together with six Republicans to replace Republican Speaker John Perzel with another Philadelphia Republican, Rep. Denny O’Brien. A key player in putting that deal together was state Rep. Josh Shapiro, a Montgomery County Democrat who later became attorney general and, on Tuesday, was elected the state’s governor.

“When you’re 102 to 101, every man’s a king,” former state Rep. Steve Nickol, a York County Republican, said at the time.