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

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

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

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

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

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

h.s = a
a.r = h
b.s = l
l.r = h
assert b.s.r.s.r.txt == "h"