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

class B:
    def __init__(self, txt: str):
        self.x: D = None
        self.u: D = None
        self.z: D = None
        self.w: C = 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.s: A = None
        self.q: C = None
        self.txt = txt

d = A("d")
m = B("m")
l = C("l")
k = D("k")
g = C("g")

d.s = m
m.x = k
m.u = k
m.z = k
m.w = l
l.o = m
k.s = d
k.q = g
g.o = m
assert g.o.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: D = None
        self.u: D = None
        self.z: D = None
        self.w: C = 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.s: A = None
        self.q: C = None
        self.txt = txt

d = A("d")
m = B("m")
l = C("l")
k = D("k")
g = C("g")

d.s = m
m.x = k
m.u = k
m.z = k
m.w = l
l.o = m
k.s = d
k.q = g
g.o = m
assert g.o.u.q.txt == "g"