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

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

c = A("c")
f = B("f")
b = A("b")
a = B("a")

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

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

c = A("c")
f = B("f")
b = A("b")
a = B("a")

c.y = a
f.r = c
b.y = f
a.r = c
assert c.y.r.y.r.txt == "c"