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

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

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

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

m = A("m")
h = B("h")
d = C("d")
l = D("l")
i = B("i")

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

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

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

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

m = A("m")
h = B("h")
d = C("d")
l = D("l")
i = B("i")

m.o = l
h.p = l
h.z = d
d.q = l
l.y = m
l.s = d
i.p = l
i.z = d
assert h.p.y.o.txt == "l"