Thousands of staff, billions of dollars and three decades of complicated relationships. Some of the world's largest banks are starting to pull back from Russia, but it's not going to be easy.

Goldman Sachs Group Inc. became the first to announce its withdrawal on Thursday, having already moved some Moscow-based staff to Dubai. JPMorgan Chase & Co. followed suit, saying it is actively unwinding its Russia business and currently engaging in limited activities in the country.

Citigroup Inc.'s roughly 3,000 workers in Russia give it by far the largest presence of any major U.S. bank in that country. It's operating "on a more limited basis given current circumstances and obligations," according to a statement Wednesday, and is continuing efforts to exit the business that began before the invasion of Ukraine.

Meanwhile Morgan Stanley is considering moving some of its 20-strong Russia-based team to the Gulf state and other financial centers, according to a person familiar with the situation. Deutsche Bank AG is assessing options for its information technology hub in Russia.

Credit Suisse Group AG, one of the first foreign banks to enter Russia in a meaningful way after the collapse of the Soviet Union, is weighing up its 125-person team in Moscow, but has yet to make any decision. In a statement Thursday, Chief Executive Officer Thomas Gottstein said the bank's board was "deeply saddened" by the war, but stopped short of saying it would withdraw.

The pressure to do more is growing. Giants in other industries, including General Electric Co., McDonald's Corp. and PricewaterhouseCoopers LLP, have already said they'll pull the plug. But banks will face a particularly difficult task of extricating themselves from a web of trades, lending agreements, and longstanding banking relationships, all the while interpreting sanctions that are multiplying almost daily.

"These financial institutions are literally WhatsApping each other about transactions, which are billions upon billions, going, 'Do we think this is captured?' 'Can we close this out?' 'We want to actually get rid of it,' or 'We want to freeze it,' or 'We want to do something else with it,'" Justine Walker, head of global sanctions and risk at ACAMS, the group for anti-financial crime professionals, told British lawmakers this week.

"They are trying to understand their legal basis for doing that, and, if they are trying to withdraw and reduce their exposure, how they can manage that in a way for their own financial stability," she said.

Banks such as Deutsche Bank and UBS Group AG bought or formed ventures with local brokers to embed themselves with Russia's business elite. In 2013, Goldman Sachs signed a three-year deal with the Russian government to help improve its international image and attract more investment.

This week, Deutsche Bank Chief Executive Officer Christian Sewing defended the lender's continuing Russian presence. "We are often asked why we are not withdrawing completely from Russia," he said in a memo to staff. "The answer is that this would go against our values. We have clients who cannot exit Russia overnight. And, as far as we can, we will continue to also support them, too, at this difficult time."

For Italian lender UniCredit SpA, abandoning Russia overnight also isn't an option, people with knowledge of the matter said. The lender offers banking services to corporate and individual clients in the country through 4,000 employees and 70 branches. You can't shutter branches that manages clients money, salaries, bills and credit lines, the people said.

A spokesman for UniCredit declined to comment.

Though Wall Street's appetite for Russia has cooled in recent years, it remains a crucial link between local companies and international markets. JPMorgan, the dominant bank for non-ruble bond issuance, has worked for the likes of Gazprom PJSC, Lukoil PJSC, and Alfa Bank AO.

The bank's international advisory council also counts Herman Gref, the CEO of Sberbank PJSC and former government minister, among its members. "Given sanctions that are now in place, he is not participating in the council," a JPMorgan spokesman said in an emailed statement.

Sberbank declined to comment.

Russia's own banks also work closely with U.S. and European lenders to access equity and debt markets. Citigroup, JPMorgan and UBS were among the top equities brokers for Sberbank CIB U.K., according to public filings for the London-based investment banking unit. Citigroup also handled a small portion of VTB PJSC's equities trading, public filings show.

These long-standing relationships have quickly become toxic. "You essentially want to avoid any kind of trading relationships with" sanctioned entities, said Virginie O'Shea, chief executive officer of Firebrand Research, a London-based capital markets research and advisory firm.

"If you look at the fines that have been meted out for KYC failures, which this tends to fall under, there are multi million dollar figures and it's gotten to the billions before in the U.S. That's scary amounts of money that the regulator will fine you," she said.

Last week, banks asked the U.K. government for more time to terminate derivative contracts with VTB, highlighting how hard it can be to sever all links, even when international law demands it.

One problem for banks is that a sanctioned entity may hold a lot of the cards. The 2002 Isda Master Agreement, a common template used in derivative deals, sets out how firms can close contracts using an "illegality" clause. However, the price of closing it out is set by the targeted entity, potentially making it very expensive to exit before sanctions take effect.

"It's a difficult problem to fix," said Robert Daniell, a derivatives lawyer at Macfarlanes LLP. "Ideally you would have negotiated the correct way to deal with these matters into your contract years ago, but not everyone fully appreciated the concern at the time."

One silver lining for banks is that their direct exposures to Russia are relatively small. For instance, HSBC Holdings Plc's Russian subsidiary had 89 billion rubles ($700 million) of assets at the end of June 2021, about 0.02% of the bank's total, according to the unit's interim accounts. Of this, about $250 million was linked to the Russian central bank, which has been sanctioned by the U.S. HSBC has just one branch left in Russia after pulling back several years ago. The bank declined to comment.

Credit Suisse said this week that its net credit exposure to Russia at the end of 2021 was 848 million Swiss francs ($914 million) and that this had been reduced since the start of the year. Deutsche Bank had a net loan exposure of about 600 million euros ($710 million) at year-end.

Citigroup was already attempting to restructure its Russian business, which has about 1,200 corporate and 500,000 consumer clients, before the outbreak of the war and has been trying to sell its local consumer banking unit. The lender has said that under a severe stress scenario it could lose about $4.9 billion.

The final cost for these companies is far from clear, though, with institutions racing to keep up with the political maneuvers.

"The folks who are issuing sanctions are drinking from a fire hose with a thimble and so they are overwhelmed as well," said Mario Mancuso, a partner at law firm Kirkland & Ellis LLP. "But that lag is producing a lot of confusion about the current state of affairs."

Harry Wilson and Lucca de Paoli report for Bloomberg News.

Copyright 2022 Bloomberg. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.