Generate query id