Fix bugs with hashes and queries when compacting to relative IRIs.