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

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

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

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

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

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

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

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

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

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

j.q = g
g.s = j
c.w = j
c.u = m
m.w = j
assert c.w.q.s.txt == "j"