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

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

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

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

m = A("m")
c = B("c")
l = C("l")
f = D("f")

m.z = c
m.y = f
c.q = m
c.z = m
c.v = l
l.x = f
f.o = c
f.p = c
assert l.x.p.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.y: D = None
        self.txt = txt

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

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

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

m = A("m")
c = B("c")
l = C("l")
f = D("f")

m.z = c
m.y = f
c.q = m
c.z = m
c.v = l
l.x = f
f.o = c
f.p = c
assert l.x.p.v.x.txt == "f"