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

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

h = A("h")
a = B("a")
j = B("j")
l = A("l")

h.o = l
a.s = j
j.s = a
l.o = h
assert a.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

h = A("h")
a = B("a")
j = B("j")
l = A("l")

h.o = l
a.s = j
j.s = a
l.o = h
assert a.s.s.s.txt == "j"