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

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

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

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

k = A("k")
d = B("d")
h = C("h")
c = D("c")
g = D("g")
f = C("f")
j = A("j")

k.u = c
d.r = c
d.x = c
d.w = h
h.z = d
c.z = f
g.z = h
f.z = d
j.u = g
assert d.x.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

k = A("k")
d = B("d")
h = C("h")
c = D("c")
g = D("g")
f = C("f")
j = A("j")

k.u = c
d.r = c
d.x = c
d.w = h
h.z = d
c.z = f
g.z = h
f.z = d
j.u = g
assert d.x.z.z.txt == "d"