<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def prefix(self, imod: YangIdentifier, mid: ModuleId) -> YangIdentifier: """Return the prefix corresponding to an implemented module. Args: imod: Name of an implemented module. mid: Identifier of the context module. Raises: ModuleNotImplemented: If `imod` is not implemented. ModuleNotRegistered: If `mid` is not registered in YANG library. ModuleNotImported: If `imod` is not imported in `mid`. """

        try:
            did = (imod, self.implement[imod])
        except KeyError:
            raise ModuleNotImplemented(imod) from None
        try:
            pmap = self.modules[mid].prefix_map
        except KeyError:
            raise ModuleNotRegistered(*mid) from None
        for p in pmap:
            if pmap[p] == did:
                return p
        raise ModuleNotImported(imod, mid)