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

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

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

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

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

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

h.r = l
l.v = h
i.v = b
b.r = l
assert h.r.v.r.v.txt == "h"