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

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

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

d = A("d")
c = B("c")
b = C("b")
f = A("f")
j = C("j")

d.w = f
c.y = j
c.r = d
c.t = d
b.v = c
b.y = c
b.w = d
f.w = d
j.v = c
j.y = c
j.w = d
assert b.y.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

d = A("d")
c = B("c")
b = C("b")
f = A("f")
j = C("j")

d.w = f
c.y = j
c.r = d
c.t = d
b.v = c
b.y = c
b.w = d
f.w = d
j.v = c
j.y = c
j.w = d
assert b.y.r.w.txt == "f"