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

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

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

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

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

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

c.y = f
a.o = l
f.y = c
k.o = a
l.o = k
assert f.y.y.y.y.txt == "f"