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

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

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

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

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

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

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

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

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

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

m.x = l
m.z = l
m.p = d
m.v = d
i.q = m
l.s = m
l.q = d
d.s = l
assert d.s.s.x.txt == "l"