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

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

h = A("h")
b = B("b")
f = A("f")
c = B("c")
l = B("l")
e = B("e")
m = B("m")

h.r = f
h.x = f
b.s = m
f.r = h
f.x = h
c.s = l
l.s = b
e.s = m
m.s = l
assert l.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.x: A = None
        self.txt = txt

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

h = A("h")
b = B("b")
f = A("f")
c = B("c")
l = B("l")
e = B("e")
m = B("m")

h.r = f
h.x = f
b.s = m
f.r = h
f.x = h
c.s = l
l.s = b
e.s = m
m.s = l
assert l.s.s.s.txt == "l"