Modified query to handle individual links