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

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

j = A("j")
b = B("b")
k = B("k")
l = B("l")
i = B("i")
f = B("f")
n = A("n")
c = A("c")

j.q = n
b.s = f
b.o = i
k.s = f
k.o = i
l.s = f
l.o = f
i.s = b
i.o = f
f.s = i
f.o = l
n.q = j
c.q = n
assert f.s.s.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

j = A("j")
b = B("b")
k = B("k")
l = B("l")
i = B("i")
f = B("f")
n = A("n")
c = A("c")

j.q = n
b.s = f
b.o = i
k.s = f
k.o = i
l.s = f
l.o = f
i.s = b
i.o = f
f.s = i
f.o = l
n.q = j
c.q = n
assert f.s.s.s.o.s.txt == "f"