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

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

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

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

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

c.u = d
c.p = l
g.y = l
d.p = g
d.r = g
d.u = l
l.z = c
l.o = d
l.v = h
f.z = c
f.o = h
f.v = d
h.p = g
h.r = g
h.u = l
assert h.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.p: D = None
        self.txt = txt

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

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

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

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

c.u = d
c.p = l
g.y = l
d.p = g
d.r = g
d.u = l
l.z = c
l.o = d
l.v = h
f.z = c
f.o = h
f.v = d
h.p = g
h.r = g
h.u = l
assert h.u.z.u.txt == "d"