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

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

l = A("l")
b = B("b")
a = A("a")
m = B("m")
h = A("h")
n = B("n")
j = A("j")

l.t = b
l.o = a
b.q = a
a.t = n
a.o = j
m.q = h
h.t = b
h.o = a
n.q = l
j.t = n
j.o = l
assert b.q.t.q.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.o: A = None
        self.txt = txt

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

l = A("l")
b = B("b")
a = A("a")
m = B("m")
h = A("h")
n = B("n")
j = A("j")

l.t = b
l.o = a
b.q = a
a.t = n
a.o = j
m.q = h
h.t = b
h.o = a
n.q = l
j.t = n
j.o = l
assert b.q.t.q.t.q.t.txt == "n"