IP of X is 165.87.0.0. Which is a class B IP-address, hence 16 bits are for network-ID(NID) and 16 bits are for host-ID(HID).
Now to divide network into 8 subnets we will have to take 3 bits from hosts so that $2^{3}$ =8 subets possible (from 000 to 111).
Number of bits taken from hosts to do subnetting= 3 bits.
Now IP address of any subnet has 19 bits for Subnet-ID part (16 NID bits + 3 extra bits taken from HID to do subnetting).
So subnet mask will have all 1’s in subnet ID part and all zeroes in host ID part
11111111.11111111.11100000.00000000 =255.255.224.0
hence, subnet mask will be 255.255.224.0