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

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

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

i.q = k
i.z = a
h.s = a
h.o = n
m.s = k
m.o = b
a.q = g
a.z = i
g.q = a
g.z = a
b.s = i
b.o = n
n.s = a
n.o = m
k.q = a
k.z = i
assert a.q.z.q.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: A = None
        self.txt = txt

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

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

i.q = k
i.z = a
h.s = a
h.o = n
m.s = k
m.o = b
a.q = g
a.z = i
g.q = a
g.z = a
b.s = i
b.o = n
n.s = a
n.o = m
k.q = a
k.z = i
assert a.q.z.q.z.q.z.txt == "a"