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

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

j = A("j")
c = B("c")
i = B("i")
e = B("e")
h = B("h")
g = A("g")
d = B("d")
m = A("m")
f = B("f")
a = A("a")

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

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

j = A("j")
c = B("c")
i = B("i")
e = B("e")
h = B("h")
g = A("g")
d = B("d")
m = A("m")
f = B("f")
a = A("a")

j.q = d
c.s = g
c.y = a
i.s = a
i.y = g
e.s = a
e.y = a
h.s = m
h.y = g
g.q = h
d.s = g
d.y = m
m.q = c
f.s = a
f.y = j
a.q = d
assert j.q.y.q.y.q.s.q.s.q.txt == "c"