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

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

f = A("f")
d = B("d")
h = B("h")
l = A("l")

f.s = h
d.t = l
h.t = f
l.s = h
assert l.s.t.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

f = A("f")
d = B("d")
h = B("h")
l = A("l")

f.s = h
d.t = l
h.t = f
l.s = h
assert l.s.t.s.t.txt == "f"