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

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

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

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

m = A("m")
g = B("g")
l = C("l")
j = D("j")

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

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

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

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

m = A("m")
g = B("g")
l = C("l")
j = D("j")

m.q = g
g.w = j
l.q = g
j.z = l
j.x = l
j.w = l
j.u = m
assert m.q.w.z.q.txt == "g"