Escape query id for prolog.