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

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

j = A("j")
b = B("b")
e = B("e")
m = B("m")
a = B("a")

j.r = m
b.y = m
e.y = b
m.y = e
a.y = b
assert m.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

j = A("j")
b = B("b")
e = B("e")
m = B("m")
a = B("a")

j.r = m
b.y = m
e.y = b
m.y = e
a.y = b
assert m.y.y.y.y.y.txt == "b"