Input:
p
min
p
max
r
min
r
max
d
min
d
max
T
num
M
num