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

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

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

k = A("k")
f = B("f")
i = C("i")
e = A("e")
d = C("d")

k.r = e
k.y = e
f.y = k
f.r = e
i.r = f
e.r = k
e.y = k
d.r = f
assert k.y.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.y: A = None
        self.txt = txt

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

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

k = A("k")
f = B("f")
i = C("i")
e = A("e")
d = C("d")

k.r = e
k.y = e
f.y = k
f.r = e
i.r = f
e.r = k
e.y = k
d.r = f
assert k.y.y.r.txt == "e"