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

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

h = A("h")
f = B("f")
m = B("m")

h.s = m
f.r = m
f.y = m
m.r = f
m.y = f
assert f.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

h = A("h")
f = B("f")
m = B("m")

h.s = m
f.r = m
f.y = m
m.r = f
m.y = f
assert f.r.r.r.txt == "m"