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

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

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

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

d = A("d")
c = B("c")
l = C("l")
b = D("b")

d.w = c
c.q = d
c.w = d
c.s = l
c.z = b
l.x = d
b.x = d
b.z = d
b.r = c
b.s = l
assert c.s.x.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

d = A("d")
c = B("c")
l = C("l")
b = D("b")

d.w = c
c.q = d
c.w = d
c.s = l
c.z = b
l.x = d
b.x = d
b.z = d
b.r = c
b.s = l
assert c.s.x.w.w.txt == "d"