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")
d = B("d")
i = B("i")

h.s = d
d.u = h
i.u = h
assert h.s.u.s.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")
d = B("d")
i = B("i")

h.s = d
d.u = h
i.u = h
assert h.s.u.s.txt == "d"