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

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

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

d = A("d")
k = B("k")
a = C("a")
b = C("b")

d.r = k
d.y = k
k.y = b
a.r = d
b.r = d
assert d.r.y.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: B = None
        self.txt = txt

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

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

d = A("d")
k = B("k")
a = C("a")
b = C("b")

d.r = k
d.y = k
k.y = b
a.r = d
b.r = d
assert d.r.y.r.r.txt == "k"