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

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

a = A("a")
i = B("i")
j = A("j")
n = B("n")
h = B("h")
k = A("k")
f = B("f")
g = A("g")
e = B("e")

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

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

a = A("a")
i = B("i")
j = A("j")
n = B("n")
h = B("h")
k = A("k")
f = B("f")
g = A("g")
e = B("e")

a.o = g
a.z = k
i.q = n
j.o = g
j.z = a
n.q = h
h.q = i
k.o = j
k.z = g
f.q = e
g.o = a
g.z = k
e.q = n
assert j.z.o.o.z.z.txt == "g"