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

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

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

k = A("k")
c = B("c")
d = C("d")
a = B("a")
i = A("i")

k.r = d
k.o = d
c.y = k
c.x = k
c.u = i
d.s = c
a.y = i
a.u = i
a.x = i
i.r = d
i.o = d
assert a.y.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.o: C = None
        self.txt = txt

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

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

k = A("k")
c = B("c")
d = C("d")
a = B("a")
i = A("i")

k.r = d
k.o = d
c.y = k
c.x = k
c.u = i
d.s = c
a.y = i
a.u = i
a.x = i
i.r = d
i.o = d
assert a.y.r.s.txt == "c"