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

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

f = A("f")
e = B("e")
j = B("j")
b = B("b")
n = B("n")
a = A("a")
h = B("h")
g = A("g")
d = A("d")

f.o = a
f.u = h
e.q = b
j.q = h
b.q = e
n.q = e
a.o = g
a.u = h
h.q = e
g.o = a
g.u = j
d.o = f
d.u = b
assert n.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.u: B = None
        self.txt = txt

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

f = A("f")
e = B("e")
j = B("j")
b = B("b")
n = B("n")
a = A("a")
h = B("h")
g = A("g")
d = A("d")

f.o = a
f.u = h
e.q = b
j.q = h
b.q = e
n.q = e
a.o = g
a.u = h
h.q = e
g.o = a
g.u = j
d.o = f
d.u = b
assert n.q.q.q.q.txt == "b"