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

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

a = A("a")
g = B("g")
i = A("i")
m = B("m")
d = A("d")
j = B("j")
k = A("k")
n = A("n")

a.o = d
a.z = j
g.o = j
i.o = k
i.z = g
m.o = g
d.o = k
d.z = g
j.o = m
k.o = a
k.z = g
n.o = a
n.z = j
assert m.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: B = None
        self.txt = txt

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

a = A("a")
g = B("g")
i = A("i")
m = B("m")
d = A("d")
j = B("j")
k = A("k")
n = A("n")

a.o = d
a.z = j
g.o = j
i.o = k
i.z = g
m.o = g
d.o = k
d.z = g
j.o = m
k.o = a
k.z = g
n.o = a
n.z = j
assert m.o.o.o.o.o.o.o.txt == "g"