query for distance working