<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _nest_wheres_for_scope(self, query, where_counts):
 """ Nest where conditions of the builder and each global scope. :type query: QueryBuilder :type where_counts: list """

        # Here, we totally remove all of the where clauses since we are going to
        # rebuild them as nested queries by slicing the groups of wheres into
        # their own sections. This is to prevent any confusing logic order.
        wheres = query.wheres

        query.wheres = []

        # We will take the first offset (typically 0) of where clauses and start
        # slicing out every scope's where clauses into their own nested where
        # groups for improved isolation of every scope's added constraints.
        previous_count = where_counts.pop(0)

        for where_count in where_counts:
            query.wheres.append(
                self._slice_where_conditions(
                    wheres, previous_count, where_count - previous_count
                )
            )

            previous_count = where_count