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

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

i = A("i")
a = B("a")
h = A("h")

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

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

i = A("i")
a = B("a")
h = A("h")

i.r = a
a.u = i
h.r = a
assert a.u.r.u.txt == "i"