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

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

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

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

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

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

f.q = a
f.o = a
j.o = l
j.x = h
a.q = h
a.o = h
l.q = a
l.o = i
i.q = l
i.o = h
n.o = f
n.x = a
h.q = i
h.o = a
assert j.o.o.q.o.o.o.o.txt == "h"