The relay carrier is typically located under the carpeting in the trunk on the left side (as you sit in the driver's seat), often near the battery. You'll likely need to remove some panels to access it.
Without a wiring diagram, identifying the correct relay is impossible. Improper identification could lead to damage. Strongly recommend finding a wiring diagram specific to your 1997 BMW 523i (E39) model (online or in a repair manual) to correctly identify the fuel pump relay. Searching online for "1997 BMW 523i E39 wiring diagram" should yield some results.