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

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

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

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

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

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

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

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

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

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

b.o = h
n.u = b
n.z = h
h.r = c
c.y = b
c.x = n
c.p = d
d.o = h
assert h.r.p.o.txt == "h"