Encode query