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

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

m = A("m")
l = B("l")
a = A("a")
g = A("g")
h = A("h")
d = B("d")
f = A("f")

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

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

m = A("m")
l = B("l")
a = A("a")
g = A("g")
h = A("h")
d = B("d")
f = A("f")

m.y = a
l.r = h
a.y = f
g.y = h
h.y = f
d.r = f
f.y = a
assert f.y.y.y.y.y.y.txt == "f"