I put each of the bags of holding Inside another, and then in a stroke of what I can only describe as genius, put the last bag inside the first.
If we want to take this seriously, just for fun, then we need to first consider what “put the last bag inside the first” means. Bags of holding are openings into extradimensional spaces, effectively portals. Theoretically, I don’t think there’s any problem with extradimensional spaces containing portals to each other in a looped manner. The problem comes with the physical act of placing one bag inside the last. In order to do so, you’d need to have a way to teleport into a known extradimensional space without using the opening. I don’t think there’s a way to do that in any edition of DnD or Pathfinder, but I could be wrong. If you can, however, then you could use exactly the same technique to retrieve any of the bags and therefore open the loop again.