Ultrametric query algorithms