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

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

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

d = A("d")
e = B("e")
h = C("h")
b = B("b")

d.y = h
e.q = b
e.v = h
h.w = e
h.t = e
h.y = d
b.q = e
b.v = h
assert b.v.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

d = A("d")
e = B("e")
h = C("h")
b = B("b")

d.y = h
e.q = b
e.v = h
h.w = e
h.t = e
h.y = d
b.q = e
b.v = h
assert b.v.t.q.txt == "b"