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

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

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

c.x = f
a.s = l
l.s = a
f.x = c
assert a.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

c.x = f
a.s = l
l.s = a
f.x = c
assert a.s.s.s.txt == "l"