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

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

b = A("b")
f = B("f")
k = A("k")
g = A("g")
l = A("l")
n = A("n")

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

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

b = A("b")
f = B("f")
k = A("k")
g = A("g")
l = A("l")
n = A("n")

b.q = f
f.o = n
f.s = b
k.q = f
g.q = f
l.q = f
n.q = f
assert g.q.s.q.txt == "f"