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

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

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

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

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

a.o = b
g.z = d
b.y = g
b.x = h
d.p = b
c.p = b
h.p = b
assert a.o.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

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

a.o = b
g.z = d
b.y = g
b.x = h
d.p = b
c.p = b
h.p = b
assert a.o.x.p.txt == "b"