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

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

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

e.z = b
e.w = b
k.r = e
b.z = e
b.w = e
assert k.r.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.w: A = None
        self.txt = txt

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

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

e.z = b
e.w = b
k.r = e
b.z = e
b.w = e
assert k.r.w.w.txt == "e"