Make sure the ancestor is maintained when queries are duplicated