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

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

e = A("e")
k = B("k")
d = A("d")
g = A("g")
a = B("a")
m = A("m")
l = A("l")

e.q = k
e.s = a
k.r = a
d.q = a
d.s = a
g.q = a
g.s = a
a.r = k
m.q = a
m.s = a
l.q = k
l.s = a
assert g.q.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.txt = txt

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

e = A("e")
k = B("k")
d = A("d")
g = A("g")
a = B("a")
m = A("m")
l = A("l")

e.q = k
e.s = a
k.r = a
d.q = a
d.s = a
g.q = a
g.s = a
a.r = k
m.q = a
m.s = a
l.q = k
l.s = a
assert g.q.r.r.r.r.txt == "a"