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

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

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

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

b = A("b")
l = B("l")
m = C("m")
i = D("i")

b.w = l
b.q = l
b.r = i
l.u = b
m.s = b
i.z = m
i.t = b
i.r = l
assert m.s.q.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: D = None
        self.q: B = None
        self.txt = txt

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

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

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

b = A("b")
l = B("l")
m = C("m")
i = D("i")

b.w = l
b.q = l
b.r = i
l.u = b
m.s = b
i.z = m
i.t = b
i.r = l
assert m.s.q.u.r.txt == "i"