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

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

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

k = A("k")
i = B("i")
d = C("d")
c = C("c")
f = B("f")
m = C("m")

k.o = i
k.y = i
k.r = f
i.y = m
i.r = k
d.v = f
c.v = i
f.y = d
f.r = k
m.v = f
assert i.r.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.y: B = None
        self.r: B = None
        self.txt = txt

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

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

k = A("k")
i = B("i")
d = C("d")
c = C("c")
f = B("f")
m = C("m")

k.o = i
k.y = i
k.r = f
i.y = m
i.r = k
d.v = f
c.v = i
f.y = d
f.r = k
m.v = f
assert i.r.r.y.txt == "d"