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

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

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

k = A("k")
d = B("d")
c = C("c")
h = A("h")

k.v = h
k.w = c
d.r = k
c.t = d
c.y = d
c.u = k
h.v = k
h.w = c
assert d.r.w.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.w: C = None
        self.txt = txt

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

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

k = A("k")
d = B("d")
c = C("c")
h = A("h")

k.v = h
k.w = c
d.r = k
c.t = d
c.y = d
c.u = k
h.v = k
h.w = c
assert d.r.w.u.w.txt == "c"