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

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

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

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

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

a.x = h
a.z = l
a.p = g
g.r = a
c.p = g
h.o = a
h.r = g
h.u = c
l.o = a
l.r = g
l.u = c
assert c.p.r.z.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.z: D = None
        self.p: B = None
        self.txt = txt

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

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

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

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

a.x = h
a.z = l
a.p = g
g.r = a
c.p = g
h.o = a
h.r = g
h.u = c
l.o = a
l.r = g
l.u = c
assert c.p.r.z.o.x.txt == "h"