What does P do in Minecraft?
@p. Selects the nearest player from the command's execution. If there are multiple nearest players, caused by them being precisely the same distance away, the player who most recently joined the server is selected. In Bedrock Edition, @p only selects players who are alive.