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

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

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

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

c = A("c")
h = B("h")
d = C("d")
i = D("i")

c.u = i
c.z = i
h.z = i
h.w = i
d.q = c
d.z = i
i.r = h
i.y = h
assert i.y.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.z: D = None
        self.txt = txt

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

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

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

c = A("c")
h = B("h")
d = C("d")
i = D("i")

c.u = i
c.z = i
h.z = i
h.w = i
d.q = c
d.z = i
i.r = h
i.y = h
assert i.y.w.r.txt == "h"