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

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

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

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

d = A("d")
h = B("h")
b = C("b")
m = D("m")

d.o = h
d.q = h
d.z = m
h.o = b
h.r = b
h.p = b
h.z = d
b.y = h
m.y = b
m.s = b
assert h.p.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.z: D = None
        self.q: B = None
        self.txt = txt

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

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

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

d = A("d")
h = B("h")
b = C("b")
m = D("m")

d.o = h
d.q = h
d.z = m
h.o = b
h.r = b
h.p = b
h.z = d
b.y = h
m.y = b
m.s = b
assert h.p.y.z.txt == "d"