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

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

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

k = A("k")
e = B("e")
c = C("c")

k.r = c
e.u = c
c.o = k
c.y = k
c.r = e
assert e.u.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

k = A("k")
e = B("e")
c = C("c")

k.r = c
e.u = c
c.o = k
c.y = k
c.r = e
assert e.u.y.r.txt == "c"