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

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

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

m = A("m")
d = B("d")
j = C("j")
h = C("h")

m.w = h
d.v = j
j.w = h
j.s = d
j.y = m
h.w = j
h.s = d
h.y = m
assert m.w.w.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

m = A("m")
d = B("d")
j = C("j")
h = C("h")

m.w = h
d.v = j
j.w = h
j.s = d
j.y = m
h.w = j
h.s = d
h.y = m
assert m.w.w.s.v.txt == "j"