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

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

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

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

m = A("m")
k = B("k")
b = C("b")
a = D("a")

m.o = k
m.z = a
k.y = b
b.z = a
a.s = m
a.u = m
a.q = k
assert m.o.y.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.z: D = None
        self.txt = txt

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

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

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

m = A("m")
k = B("k")
b = C("b")
a = D("a")

m.o = k
m.z = a
k.y = b
b.z = a
a.s = m
a.u = m
a.q = k
assert m.o.y.z.q.txt == "k"