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

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

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

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

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

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

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