Free trade between Canada and Mexico is in part an accident of history: two nations, each the other’s afterthought, came together in their shared race to capitalize on the U.S. market. Now, after President Donald Trump threatened to leave the North American Free Trade Agreement, the pact’s junior partners are working more closely than ever to save it. Trump has called Nafta the worst trade deal in history and blames it for millions of lost manufacturing jobs. Canada and Mexico have overcome distance and patched over differences to become its last line of defense, and the real test is approaching. Trump’s ability to dictate terms of a new deal will hinge in part on solidarity among his two partners. Canada and Mexico could team up to defend core tenets, or find themselves tempted to sell the other out issue-by-issue in a classic prisoner’s dilemma. And they remain strange bedfellows. It’s “desirable” for the two to work together, said Jorge Castaneda, a former Mexican foreign minister. “I’m not sure that it’s that easy, because many of the most worrisome issues for one country are not that important for the other.” Mexico could be called upon to back Canada’s red-line issues, like agriculture and the Chapter 19 dispute-settlement mechanism. Canada and the U.S., meanwhile, are already calling for labor and environmental reforms aimed at spurring change in Mexico. Another flashpoint is timing, with Mexico wanting a quick deal ahead of its president election while Canada is in no rush. Strength in Numbers Irritants remain on all sides. The southern partner bore the brunt of Trump’s ire over Nafta thanks to factories he says were drawn across the border by the allure of low wages. The northern partner, though less of a target, has clashed with the U.S. over softwood lumber, dairy and aircraft production. While each nation may be tempted to elevate its own priorities when talks begin in Washington on Aug. 16, there can be strength in numbers. Canada and Mexico may be best served by presenting a united front, as they did in April when the president opted to renegotiate the deal rather than tear it up right away, and persuading Trump to accept an evolution in Nafta instead of a full-on trade revolution. There are signals Trump is warming to a pan-North America approach. At meetings in Canada and Mexico, the junior partners agreed to stick together on the broad goal of protecting and deepening Nafta’s benefits, according to two Mexican government officials. Canadian government officials, meanwhile, downplayed the Mexican outreach efforts as more routine than any silver bullet, saying Prime Minister Justin Trudeau’s team is building whatever ties it can, including a heavy focus on lobbying the U.S. All the officials asked not to be identified discussing closed-door conversations. Mexico has perhaps been the biggest beneficiary of Nafta in relative terms. While Canada more than doubled exports to the U.S. to $278 billion annually under the deal, Mexico’s exports surged seven-fold to $294 billion. The U.S. had a $63 billion trade deficit in goods and services with Mexico last year, compared with a $7.7 billion surplus with Canada, according to the U.S. Bureau of Economic Analysis. The U.S. has made reduction of trade deficits a top priority of its Nafta overhaul. The deal’s three-party structure largely resulted from a defensive move by the Canadians two decades ago. When the U.S. began to negotiate trade with Mexico in the early 1990s, Canada joined the talks in order to defend the advantages of its own agreement with the U.S., signed just a few years earlier. For both Canada and Mexico, the relationship with the U.S. has remained far more important than their relationship with each other. Visa Dispute The issue of Mexican immigration, highlighted by Trump’s demand the nation pay for a border wall, also has caused friction with Canada. In 2009, then-Prime Minister Stephen Harper slapped a visa requirement on Mexican travelers to stem a spike in bogus refugee claims. Mexico protested and ties became strained, in part contributing to Harper’s cancellation of a so-called Three Amigos summit in 2015. The relationship turned a corner when Mexican President Enrique Pena Nieto visited Ottawa a year ago and Trudeau said he would remove the visa rule in exchange for Mexico lifting restrictions on Canadian beef. Trump’s differing approach to his Nafta partners has already put their rapprochement to the test. Pena Nieto canceled a January visit to Washington due to Trump’s wall demand, and that month Canada’s envoy in Washington mused about “bilateral” solutions that would cut Mexico out.  Trudeau also faces domestic pressure to do just that. “The status quo is a disaster,” according to Jerry Dias, who heads Unifor, a major Canadian labor group representing auto workers. “Donald Trump and I don’t agree on much,” he said. “But he’s right when he says the American workers got shafted on Nafta.” ‘Tweaking’ or More? In February, less than a month after Pena Nieto’s canceled trip, Trudeau was received at the White House with open arms. Trump pledged only a “tweaking” of Nafta for Canada, whose trade relationship with the U.S. he called “much less severe” than the problems with Mexico. Since then, however, Trudeau and his envoys have made clear Nafta must remain a three-party deal. The message has been repeatedly reinforced by Foreign Minster Chrystia Freeland, who built a rapport with Mexico’s top Nafta negotiator, Economy Minister Ildefonso Guajardo, during talks for finalizing the Trans-Pacific Partnership trade pact.  And yet the temptation to undercut each other will remain strong. Canada isn’t immune to anti-Mexico sentiment. Refugee claims by Mexicans, meanwhile, could rise again and threaten to become a political problem once more. “Both Canada and Mexico are very committed to protecting and deepening Nafta,” said Shannon O’Neil, a senior fellow at the Council on Foreign Relations in New York. “The question is when you actually get to the table, do they make common cause broadly and coherently and cohesively?”