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

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

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

class D:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

l = A("l")
e = B("e")
g = C("g")
d = D("d")

l.y = g
e.r = l
e.z = d
g.z = l
d.w = e
assert g.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

l = A("l")
e = B("e")
g = C("g")
d = D("d")

l.y = g
e.r = l
e.z = d
g.z = l
d.w = e
assert g.z.y.z.txt == "l"