State Sen. Bryce Reeves (R-Spotsylvania), who is running for lieutenant governor, visits his political director, Matt Gruda, who camped out outside Board of Elections headquarters for 63 hours, hoping to ensure Reeves got top billing on the primary ballot. Turns out placement will be decided by lottery. (N/A/Bryce Reeves campaign)

Braving bitter cold, campaign staffers for state Sen. Bryce E. Reeves camped out all weekend in front of the state Board of Elections, determined to get his name listed first on the ballot for the June 13 GOP primary for lieutenant governor of Virginia.

Sunday night, they got some company on the sidewalk. Staffers for gubernatorial hopeful Corey A. Stewart lined up behind them, confident for the next 12 bone-chilling hours that they, too, had snagged the top ballot position in their race.

Under state code, name placement on primary ballots is determined by the order in which the requisite paperwork is filed. In the competition to get candidates top billing, playing out on the coldest weekend of the year, it seemed the race would go to the hardiest.

But the frigid vigils were for naught.

Turns out, there’s a little wiggle room in the state’s first-come, first-listed approach. If two or more candidates file simultaneously, state code says the order is determined by drawing lots. But the code does not define “simultaneously.”

The Reeves and Stewart campaigns were at the front of the line well before anyone else showed up. But since, under state code, the board cannot start accepting candidate filings until noon on March 13, elections officials called it a tie for anyone in line by that hour.

The campaigns undertook their late-winter camp-outs on advice from a state elections policy analyst, who had assured them that the first in line would be rewarded with prime ballot placement. State Elections Commissioner Ed Cortés acknowledged Monday afternoon that the analyst had gotten it wrong.

“I apologize to the Reeves campaign and the other folks that were there this morning,” Cortés said. “They were out there based on something our staff told them.”

Outfitted with lawn chairs and sleeping bags, Reeves’s staffers began their wait outside the board’s downtown Richmond offices Friday, despite lows in the 20s.

“It was a lot of fun,” said Matt Gruda, Reeves’s political director. “There were four or five of us actually stationed outside, a lot of friendly people bringing us food, drinks, coffee, hot chocolate.”

But after 63 hours of that “fun,” Gruda and the rest thought there also would be a payoff. So did Stewart’s team, which showed up about 8 p.m. Sunday.

A little before 8 a.m. Monday, shortly before the board’s office doors opened, two rival campaigns arrived. There was Del. Glenn R. Davis Jr. (Virginia Beach), who is running against Reeves (Spotsylvania) for lieutenant governor. And there were staffers for former Republican National Committee chairman Ed Gillespie, who is running against Stewart for governor.

The Reeves and Stewart campaigns were sure they had them beat by a mile. But Cortés called it a tie.

Cortés said name placement for those candidates at the office by noon Monday will be decided with a public drawing on April 5.

The decision drew howls from Stewart, chairman of the Prince William Board of County Supervisors, who released a statement accusing Gillespie of “rigging” the process. Reeves said he was consulting a lawyer about a potential legal challenge.

The episode highlights the vigorous nature of the GOP primaries in a year when three statewide offices are up for grabs. Higher placement of a candidate’s name is thought to provide a boost, but only a small one.

It also gave the campaigns a chance to take swings at each other — and at the elections department of Gov. Terry McAuliffe (D), which the GOP blasted last fall for registration woes ahead of the presidential contest.

Stewart, who led Donald Trump’s Virginia campaign until he was ousted for participating in a protest against the Republican National Committee — or “establishment pukes” as he referred to its members — suggested the state GOP was in cahoots with Gillespie because it agreed with Cortés’s interpretation.

“Ed Gillespie and his elitist team of lawyers are manipulating the Virginia Board of Elections in a last-ditch, rule-breaking effort to have Ed’s name placed at the top of the ballot,” Stewart said in a news release.

The state GOP did not respond to a request for comment. Gillespie’s spokesman said Stewart, a lawyer, should have read the state code.

“The law is clear,” said Gillespie spokesman Matt Moran. “Chairman Stewart never should have taken bad advice from one of Terry McAuliffe’s lawyers, but now I guess we know why the Trump campaign fired him for incompetence.”

Reeves said the episode showed his staff’s grit.

“The dedication and loyalty of my team to our cause is unparalleled and stands above the rest,” he said.

But Davis suggested it demonstrated something else. “I feel really bad for Reeves [staffers], but knowing the state code, we know the only thing that mattered was to be there by noon,” he said. “Campaigns have to work hard. But most importantly, you have to work smart.”

Some candidates for statewide office avoided the whole drama by being stragglers. Both Democrats seeking to succeed McAuliffe — Lt. Gov. Ralph Northam and former congressman Tom Perriello — are still collecting the required 10,000 signatures.

So is state Sen. Jill Holtzman Vogel (R-Fauquier), who is running for lieutenant governor, and two additional Republicans in the governor’s race, state Sen. Frank W. Wagner (Virginia Beach) and Nelson County distillery owner Denver Riggleman.

Since their paperwork was not submitted Monday, their names will not be part of the drawing. They will be listed on the ballot according to when they file.

“I’m ok batting cleanup for the Commonwealth,” Riggleman said in a text message. “If I’m the last on the ballot, so be it. Save the best for last.”