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

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

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

m.y = h
f.v = h
f.r = d
a.y = m
d.y = h
l.v = h
l.r = a
h.y = m
assert a.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.v: A = None
        self.r: A = None
        self.txt = txt

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

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