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

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

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

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

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

d.r = c
i.z = d
i.y = d
i.u = c
i.w = b
c.q = b
b.r = d
b.t = c
b.x = c
b.y = c
assert c.q.y.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

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

d.r = c
i.z = d
i.y = d
i.u = c
i.w = b
c.q = b
b.r = d
b.t = c
b.x = c
b.y = c
assert c.q.y.q.r.txt == "d"