implemented minimum query