class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: A = None
        self.z: A = None
        self.txt = txt

e = A("e")
k = B("k")
h = A("h")

e.s = h
k.s = h
k.z = e
h.s = e
assert h.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: A = None
        self.z: A = None
        self.txt = txt

e = A("e")
k = B("k")
h = A("h")

e.s = h
k.s = h
k.z = e
h.s = e
assert h.s.s.s.txt == "e"