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

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

m = A("m")
l = B("l")
e = B("e")
f = B("f")
a = B("a")

m.y = a
m.q = f
l.q = a
e.q = f
f.q = a
a.q = f
assert m.y.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

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

m = A("m")
l = B("l")
e = B("e")
f = B("f")
a = B("a")

m.y = a
m.q = f
l.q = a
e.q = f
f.q = a
a.q = f
assert m.y.q.q.q.q.txt == "a"