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

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

h = A("h")
j = B("j")
f = B("f")

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

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

h = A("h")
j = B("j")
f = B("f")

h.s = f
j.u = h
f.u = h
assert f.u.s.u.txt == "h"