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

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

i = A("i")
a = B("a")
k = A("k")
h = B("h")
e = B("e")
g = A("g")
m = B("m")

i.q = k
i.p = m
a.x = m
a.s = m
k.q = g
k.p = a
h.x = a
h.s = m
e.x = a
e.s = h
g.q = i
g.p = h
m.x = h
m.s = e
assert g.p.x.s.x.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.p: B = None
        self.txt = txt

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

i = A("i")
a = B("a")
k = A("k")
h = B("h")
e = B("e")
g = A("g")
m = B("m")

i.q = k
i.p = m
a.x = m
a.s = m
k.q = g
k.p = a
h.x = a
h.s = m
e.x = a
e.s = h
g.q = i
g.p = h
m.x = h
m.s = e
assert g.p.x.s.x.s.x.s.txt == "m"