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

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

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

a = A("a")
c = B("c")
n = C("n")
d = B("d")

a.x = c
a.w = n
c.v = a
c.z = a
c.r = d
n.w = a
d.v = a
d.z = a
d.r = c
assert a.w.w.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.w: C = None
        self.txt = txt

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

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

a = A("a")
c = B("c")
n = C("n")
d = B("d")

a.x = c
a.w = n
c.v = a
c.z = a
c.r = d
n.w = a
d.v = a
d.z = a
d.r = c
assert a.w.w.x.r.txt == "d"