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

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

g = A("g")
l = B("l")
f = A("f")
c = B("c")
d = B("d")
j = B("j")
e = B("e")
n = A("n")
h = B("h")
m = B("m")

g.s = l
l.q = e
f.s = m
c.q = e
d.q = j
j.q = e
e.q = h
n.s = m
h.q = j
m.q = c
assert h.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

g = A("g")
l = B("l")
f = A("f")
c = B("c")
d = B("d")
j = B("j")
e = B("e")
n = A("n")
h = B("h")
m = B("m")

g.s = l
l.q = e
f.s = m
c.q = e
d.q = j
j.q = e
e.q = h
n.s = m
h.q = j
m.q = c
assert h.q.q.q.q.q.txt == "e"