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

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

a = A("a")
g = B("g")
b = B("b")
h = B("h")
l = A("l")

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

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

a = A("a")
g = B("g")
b = B("b")
h = B("h")
l = A("l")

a.r = l
g.r = a
b.r = a
h.r = l
l.r = a
assert a.r.r.r.txt == "l"