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

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

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

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

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

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

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

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

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

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

f.x = m
f.q = m
f.u = m
f.s = d
m.x = f
b.o = m
d.z = f
assert f.u.x.s.txt == "d"