Calculate Bilayer Thickness using gmx distance

GROMACS version: 2023.1
GROMACS modification: No
Hi, I am trying to calculate lipid bilayer thickness using gmx distance, but when I tried to make the index file which contained the phosphate in the top and bottom bilayer the result is like here. Can you help me the right way to make the index file for this one?
Command to make the index file:
I generated a selection.dat file which includes:
top_p = name P and (z > 5);
bot_p = name P and (z < 5);
top_p;
bot_p;
Then commanded:
gmx select -sf selection.dat -f md.xtc -s md.tpr -on p_index.ndx
gmx distance -f md.xtc -s md.tpr -n p_index.ndx -select ‘com of group 0 plus com of group 1’ -oxyz po4_distance.xvg
source: https://www.researchgate.net/post/How-do-I-calculate-bilayer-thickness-with-Gromacs-distance-command