<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_for_each(self, db, safe_mode=False, extra=None):
 """Builds the for-each context."""

        result = dict()
        for var, query in iteritems(self.for_each):
            result[var] = db.query(
                query,
                additional_locals=extra,
                safe_mode=safe_mode
            )
        return result