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

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

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

i = A("i")
b = B("b")
h = C("h")
c = C("c")

i.r = b
b.y = c
b.o = h
h.y = b
h.r = c
h.x = i
c.y = b
c.r = h
c.x = i
assert h.r.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

i = A("i")
b = B("b")
h = C("h")
c = C("c")

i.r = b
b.y = c
b.o = h
h.y = b
h.r = c
h.x = i
c.y = b
c.r = h
c.x = i
assert h.r.x.r.txt == "b"