HARRISBURG — Pennsylvania Supreme Court justices on Wednesday interrogated lawyers defending the way the state's congressional districts were drawn, a map opponents have challenged as illegally shaped to benefit Republicans, who hold a majority of its seats in the U.S. House.

Based on the tenor of their questions, a majority of the court, which has five Democrats and two Republicans, appeared open to the argument that Pennsylvania's congressional districts are illegally gerrymandered. A group of Democratic voters has asked the court to overturn the map and order a new one drawn before the 2018 elections, in one of several such lawsuits nationwide.

The justices, while acknowledging that politics played a role in the boundary-drawing, must decide whether those political concerns crossed the line and deprived Democratic voters of their constitutional rights.

"A test has, I think, eluded every court that has tried to grapple with this," Justice Max Baer, who ran as a Democrat, said at one point during the 2½-hour hearing. Over and over, justices asked attorneys for the 18 Democratic voters who brought the suit and the leaders of the Republican-controlled legislature what the test should be.

Whatever the court's decision, it will have implications for this year's midterm elections, when forecasts indicate Democrats have an outside chance of retaking the House. The justices are expected to rule within the next few weeks.

In Pennsylvania, the legislature draws district boundaries. Attorneys for the plaintiffs argue that the 2011 map, drawn when the legislature and the executive branch were controlled by Republicans, was designed to give the GOP an unfair advantage, depriving their clients of their rights to free expression.

Some who have filed briefs alongside the voters have also argued that the maps violate the right to a "free and equal election," as promised under the state constitution. They note that in the three congressional elections held since the maps were drawn, the same 13 of 18 seats have gone to Republicans, even though the overall vote in the state has been about evenly split.

David Gersch, the attorney representing the voters, listed a number of oddly shaped districts that he described as "nationally infamous" and said, "There's no explanation for why the map is made that way," except to favor Republicans.

The justices peppered him and the attorney for Gov. Wolf, a Democrat who has sided with the voters, with questions about how to determine when a map has been so heavily gerrymandered that it becomes discriminatory; attorneys suggested that traditional measures used by political scientists could provide guidance.

Justices also questioned whether fair maps could be withdrawn in time for the May 15 primary, or whether the primary could reasonably and fairly be pushed back to July, August or September. Some asked whether a ruling would affect the March special election to replace former U.S. Rep. Tim Murphy, a southwestern Pennsylvania Republican who resigned amid a scandal. The Wolf administration lawyer said the race in Murphy's former district would not be affected.

Justice Debra Todd, who ran as a Democrat, told the attorneys: "We want to make sure that if we were to order that [a redrawing], we are not ordering the impossible."

When attorneys for Republican leaders approached the microphone to argue, the debate grew more tense.

Their side opened with arguments from attorney Jason Torchinsky, who said that 50 percent of the maps presented by an expert would have pitted U.S. Rep. Bob Brady, the veteran Philadelphia Democrat, against an incumbent congressman. He said that was "unrealistic," pointing to the fact that Brady's longevity in the House could be good for Pennsylvania should the Democrats retake the House.

Justice David Wecht, who ran as a Democrat, told the attorney he was addressing the court "as if we were sitting here in a caucus room drawing a district, but we are not." The justices, he said, should not be concerned with specific congressmen.

Torchinsky was followed by attorney Mark Braden, who represents House Speaker Mike Turzai (R., Allegheny). Braden warned the justices that the voters who brought the suit were "inviting you into the political thicket." He noted that the state constitution says that the legislature should draw the districts.

"Shock of shock, they use politics to do that," he said. "This is an invitation you need to not accept."

He added that the court would be "impaling" itself and risking its credibility if it were to overturn the maps.

"That sounds a lot like the argument made in Brown v. Board of Education," Wecht said, referencing the 1954 U.S. Supreme Court decision that declared separate schools for black and white children  unconstitutional.

Braden pointed out that the discrimination in that case revolved around race. Wecht shot back that the state Supreme Court had recently ruled that the equal protection provision of the state constitution — one likely to play a role in this case — can apply to other factors.

When the clock struck noon, the justices ended the hearing. Gersch, the attorney representing the voters, told reporters he was encouraged by the detailed questions the justices asked. His comments were met by applause by people who had come in to watch the hearing.

Drew Crompton, an attorney for the Senate Republicans, said he wasn't ready to concede. If the maps are overturned, he said, his team will look at options for an appeal.

Staff Reporter Jonathan Lai contributed to this report.