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

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

d = A("d")
k = B("k")
e = B("e")
c = A("c")

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

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

d = A("d")
k = B("k")
e = B("e")
c = A("c")

d.x = c
k.r = d
k.z = c
e.r = d
e.z = d
c.x = d
assert k.r.x.x.txt == "d"