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

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

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

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

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

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

n.o = m
n.q = f
m.y = a
a.o = j
a.q = n
j.y = b
l.y = b
k.y = f
b.o = l
b.q = f
f.o = m
f.q = n
assert n.q.q.q.q.o.txt == "m"